About

Posted August 17, 2004
← Go to home page
← See all articles

Article

Better Anything Rotator

A couple of weeks ago, Dan Benjamin introduced his Better Image Rotator (BIR) as an new and improved way to display a random image on a web site. The script, building upon his original rotator, allows you to associate a URL, alternate text and a title with each picture. The resulting <img> tag included these extra bits. While adding a picture to the mix was much easier with the old script (just dump a file on the server et voila!), the new one is not hard. And it’s much more interesting. Photos still live in a server directory, but the associated info is in an INI file — just like the win.ini and system.ini files hanging around old versions of Windows. The file format looks like this:

[ALA]
src = img/ala.jpg
alt = ALA Logo
url = http://alistapart.com/
title = A List Apart

[Scientist]
src = img/scientist.png
alt = Pic of a scientist
url = http://hivelogic.com/
title = Hivelogic

Pretty simple, eh?

Dan’s BIR could not have arrived at a better time for me — I had been contemplating how to rotate photos with captions on the new UW Arboretum site when his article showed up on A List Apart. But still, it wasn’t quite right. See, I need to store (and rotate) not only photos and alt text, but a full caption as well.

After a few emails with Dan, I was in business. I added another line to each block in the INI configuration file, then modified the PHP script to accommodate a new field called “caption.”

But yesterday, I was looking for an easy way to rotate quotes (testimonials) on a redesign for Partners in Place. A “real” database would have worked, but using BIR was much easier. So I ripped apart the INI file, replacing four image-oriented fields with two quote-oriented ones. Then I modified the PHP file, replacing all traces of “image” with a generic “item” or “row.” The result: My Better Anything Rotator.

I’m offering the modified script for anyone who would like to use it. Things are mostly as Dan intended them, but I must make a few notes:

I probably forgot something. Anyway, take a look at my demo and feel free to use/abuse/tweak if it will help with a project. The following files are available:

* * *

DISCLAIMER: I am not a programmer and have only a basic understanding of PHP. This script was created by tweaking and hacking Dan Benjamin’s work, not because I actually understand this stuff. None the less, feel free to contact me with corrections/questions/requests.