10
Apr/056
Apr/056
Changed Header Image
I’ve made a simple small change in the top header image. I’ve created 7 images and every time you reload the page a php script loads one of the 7 images randomly.
How I did it?
I’ve created 7 images and uploaded them in my theme images folder. I then removed my CSS header code and pasted it into the header template editing it to look like this.
#header {
background: url("< ?php bloginfo('stylesheet_directory'); ?>/images/head0< ?php echo rand(1, 7); ?>.jpg" ) no-repeat bottom center;
}
And that’s it. The php rand(1, 7); function creates a random number from 1 to 7 inclusive and that loads the appropriate picture. Simple yet effective.
Comments (6)
Trackbacks (1) ( subscribe to comments on this post )



















April 13th, 2005
Well, it’s not exactly as you say it is
It loads one of the seven images randomly.
April 13th, 2005
Edited. Thanks for the correction.
April 30th, 2005
Ok i tried the code you show (thanks by the way!!) but images won’t show up and when I view source this is what i get:
#header { background: url("http://www.jeremiahandsarahowen.com/wp-content/themes/mx4_theme/images/head01.jpg�) no-repeat bottom center;
}
any ideas why I am getting that goofy acsii question mark there?? Thanks!
April 30th, 2005
I would imagine that you get that ascii because your quotes ( ” ) are being translated into ascii try checking your source to see if you get something like &(number);.
Other than that I don’t realy know. Maybe it would help if you typed the code other than copy paste.
May 4th, 2005
Yup that was it… I typed it and it was fine…
May 4th, 2005
Glad I could help