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.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>