I have been working on WordPress for the last several months, I have been very impressed with everything this platform can accomplish. I love the fact that I can have our business people work on the web site and produce and publish content. The ability to write plugins I like a lot also.

I had to write an ad rotator that could display in a side bar on the website, the side bar in question was not able to accept widgets. So, I opened the functions.php file in my theme directory and added the function below.

This function will read all files in a specific directory, in this case the rotator directory right off the root of the web site. Only put image files in this directory, I did not add anything to handle other types of files.

The image file will be displayed and also wrapped in an anchor tag, the url will be built based on a static base url with the filename of the image added. For example, an image file named welcome-to-wordpress.jpg would have a anchor with the url of info.rainaldi.org/welcome-to-wordpres/.

I am using the random function built into PHP to determine what image to show, this is accomplished by loading all files from a directory into and array and calling the random function supply a min and max value. The min value is skip ‘.’ and ‘..’and the max is the highest indexer in the array.

To use this function I add a call to ImageLinkRotator() to the theme page in the location desired.