WordPress Themes – Random Image Header

While working on a theme for WordPress lately.I ran across the problem of wanting a random header image on the top of the page, but how to do it?  After looking around for a simple, fast script, I ran across, who else, but Matt Mullenweg’s page.

Matt wrote a small, fast script that will look at the content of a directory, then randomly returns the a image’s URI.

In Matt’s own words:

This is your standard random image script that takes a slightly different approach than most, namely using standard HTTP headers instead of reading the file through the script.

So to integrate this script into your page, all you need to do is change the images name to random.php, see below.

<img title="<?php bloginfo('name'); ?> Random Header Image" src="<?php bloginfo('template_url'); ?>/header1.jpg" alt=""/>

Change too:

<img title="<?php bloginfo('name'); ?> Random Header Image" src="<?php bloginfo('template_url'); ?>/rotate.php" alt="">

Matt Mullenweg’s script may be found at: http://ma.tt/scripts/randomimage

This is your standard random image script that takes a slightly different approach than most, namely using standard HTTP headers instead of reading the file through the script.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s