I saw some people looking to display a different image on each WordPress Page instead of the site wide random images. Read on...
First, I'll give you the code and explain how it works. That way, you'll understand it better and can easily adapt it to your site.
The Code
<?php if (is_page('28')) { ?>
<img src="<?php bloginfo('template_url'); ?>/headers/image1.jpg" width="920" alt="<?php bloginfo('name'); ?> header image" />
<?php } elseif (is_page('26')) { ?>
<img src="<?php bloginfo('template_url'); ?>/headers/image2.jpg" width="920" alt="<?php bloginfo('name'); ?> header image" />
<?php } elseif (is_page('30')) { ?>
<img src="<?php bloginfo('template_url'); ?>/headers/image3.jpg" width="920" alt="<?php bloginfo('name'); ?> header image" />
<?php } else { ?>
<img src="<?php bloginfo('template_url'); ?>/rotating.php?image=<?php echo mt_rand(0,100); ?>" width="920" alt="<?php bloginfo('name'); ?> Rotating Header Image" title="<?php bloginfo('name'); ?> Random Header Image" />
<?php } ?>
I have 3 Pages here. With the above code, I'm telling the theme to display a given image on each of those 3 Pages and to display random images everywhere else.
- 1st two lines tell the theme to display
image1.jpgon a Page with ID28. - next two lines tell it to display
image2.jpgon a Page with ID26and so on. - Last two lines (marked in blue) tell it to display random images everywhere else.
How to
- Upload your header images into the headers folder in your PrimePress directory.
- Open your
header-images.phpin your WordPress theme editor, delete the already existing code and paste the above code block in there. - Change the Page ID and the image file name according to your site. (parts marked in red)
Some Notes
Chances are, you want to do this on more than three pages. Just copy (duplicate) the lines marked in green, paste them right below (but above lines marked in blue) and change the ID and filename.
If you have permalinks turned on, you can also type in the post-slug in place of the Page IDs.
