March 21, 2009

How to Make Header Images Random

Courtesy of: http://www.bigsquaredot.com

Courtesy of: http://www.bigsquaredot.com

So you want to make the header images on your blog random huh? Well, you can do this extremely easy. Here are the steps to achieve this simple task.

1) Get the Images

Okay, get 4 images that you want to use on your blog. Here’s what I’ll be using:

header1.jpg

header2.jpg

header3.jpg

header4.jpg

Put all of these images in a folder called images in your theme folder. If you don’t have that folder yet, go ahead and create one now.

2) Randomizing the Images

Put this code in your header.php file just below the tag:

<?php
$header_image = rand(1,4);
?>

So if you more or less images, you can change 4 to whatever it is.

3) Randomizing in the Header

If you’re using a more professional WordPress theme, then more than likely the header image is going to be called in from the .css file using a header DIV. Well, you’re going to have to get rid of that, and use this old-school HTML technique.

Use this code to pull the header images into your theme:

<img src="<? bloginfo('template_directory'); ?>/images/blogtop-<? echo $header_image; ?>.gif" alt="header" />

So that concludes our random header image tutorial for WordPress. You can pretty much use the same technique, but modify it a little bit, if you want to use this on a static HTML/CSS website, a forum, or maybe even another CMS!


Previous Post and Next Post


Try HostGator Webhosting for 1 cent for the 1st Month Click here and enter "wordpress"

Leave a reply

* means field is required.

*

*