How To Have Random, Rotating Images In Your Blog Header
As part of my new header design for this blog, I am using a series of 12 header images which rotate randomly.
I’ve had a few people comment on that and wonder how I did it. It is actually VERY easy to do.
First, you create the images you want in your header. Make them all the same dimensions that way they can change without making your layout different.
When you name the images, give each of them a numeric file name. For example:
- topphoto_1.jpg
- topphoto_2.jpg
- topphoto_3.jpg
- and so on.
Make sure not to skip any numbers. It has to be a constant series of numbers.
Now, you modify your blog theme. In the section of your header.php file where you want this image to appear, use this instead:
<img src=”topphoto_<?php echo rand(1,X); ?>.jpg” width=”123” height=”123” />
Now, the most important part of that is the PHP code inside of the filename. What you’re doing is telling PHP to give you a random number between 1 and X. Replace X with the number of images you have available. In my case, I have 12 header images, so I would use rand(1,12). Also, make sure you use the actual height and width of your images in the HTML.
That’s all there is to it, guys. No javascript necessary. No plug-ins, either.
If you enjoyed this article, you might also like...
- Using Gravatars On Your Blog – Why And How
- Insiders: An Opt-In Technique Worth Testing. I Will Be. :-)
- How To Use a Custom Page Template In Wordpress
- Robots.Txt – The Often Forgotten File
- How To: Putting the Full Blog Post Into An Aweber Blog Broadcast
Get your copy of the Six Figure Blogger Blueprint.
You'll Discover...
- 3 vital questions to pick the right niche.
- The layout for funneling traffic into your blog.
- How this blog generates thousands of dollars monthly - without a single banner ad.
-
Heath Mullikin
-
Leslie Bergstrom
-
Agent Deepak
-
Paul Pope Sr.
-
cadilacjax
-
Steve
-
Patrice
-
Melvin
-
Izzat Aziz

I'm David Risley. I've been making my living as a blogger for over a decade. Blogging is my business and how I support my family. With this blog, I'm just gettin' REAL and telling you how this business works.









