Getting started with Smarty templating

Posted on Thursday 7 May 2009

A few days ago I started using smarty. I was amazed by what you can do with this templating engine. Smarty is a templating engine written in php which allows you to easily split the PHP code from your html code. The smarty developers call it a "Template/Presentation Framework” because it‘s not just a tag replacing template engine. Templating is especially useful when you work with web designers who have little or no knowledge of PHP. They can easily change the html code in the tpl files without being bombarded with PHP code. I am a web developer and I started using a templating class which just enabled me to assign variables and blocks. I now use smarty for my CMS. It took me about 2,5 days to implement it because the templating class I used, worked completely different from Smarty. Smarty enables me to loop through arrays, use modifiers (which are basically custom PHP functions that work within smarty), cache files, debugging and so much more.

Read more →

Add tweets and get latest tweets from Twitter using Twitter API

Posted on Monday 27 April 2009

This weekend I made a twitter module for our CMS. This was fairly easy to do. I included the files. You can download them below. I think the curl module has to be installed on your webserver to use it. You can get your latest posted tweet with the variable $last_tweet. To echo all of your latest tweets use the variable $twitter_tweets. It also includes a javascript file to limit the amount of characters. Twitter only allows tweets of 140 characters. Don‘t forget to change your twitter credentials on top of the index.php file. Change the $twitter_username to your username and the $twitter_psw to your password. 

Read more →

PHP XML sitemap generator

Posted on Monday 20 April 2009

Recently I came across a php script that automatically generates an XML sitemap.The script crawls through a website, searching for href‘s within the same domain. I‘ve altered the script a bit so it lets google know when a new xml sitemap has been generated. When your website changes a lot you should frequently update your sitemap. By using this sitemap generator you can do this without any hassle.

You can change the location of the sitemap within the index.php. Just alter the variable $filename to your location (line 451 or so). You should also change the paramater $url_xml in the pingGoogle function on line 494 to the full path of the sitemap (e.g. http://www.domain.com/sitemap.xml). Otherwise you‘ll get a 400 error on pinging google. Make sure sitemap.xml has write permissions, so chmod sitemap.xml to 777.

Read more →

Focus on first form input field or textarea onload page using jQuery

Posted on Thursday 9 April 2009

This Javascript basically only sets the focus on the first form input field or textarea of a form when the page is loaded. i use this in my CMS because I hate it when I e.g. have to manually type in a list of emails in a form always click in the first input field to start typing again. This script uses jQuery.

Read more →

Limiting the length of characters in a textarea using javascript

Posted on Wednesday 8 April 2009

I use a javascript that‘s very easy to use. All you need to do is include the JS file and add a maxlength attribute to a textarea element with the amount of characters you want to allow. That‘s it. I use this to limit the input of characters for page meta-tags to 160 characters.

e.g.

< textarea cols="60" name="field" rows="3" maxlength="160">

And add onload=‘setMaxLength()’ to the body tag:

< body onload="setMaxLength()">

Download files

Read more →

How to make a simple jQuery Ajax request

Posted on Monday 9 March 2009


jQuery is an amazing javascript framework. It‘s makes Ajax so easy. You don‘t have to know anything about Ajax to use it. I‘ve made a simple example on how to use jQuery to make an Ajax request. First, start with creating a database with the name jquery_ajax. I‘ve included the sql dump in the example. In the database there‘s 1 table, called comments. Then we‘ll need to include jQuery in our html file. Next, add a div with a class loading. In the css file the loading class is hidden so we‘ll use

display: none

to hide it. You can call the jQuery.approve() function on whatever DOM element you like. Here we‘ll pass on 1 parameter (the id of the comment to be approved) to the function.

input id=“1” onclick=“jQuery.approve(1);” type=“submit” value=“Awaiting approval”

Read more →