Changing Header Images Dynamically

Status
Not open for further replies.

ArtDeco

Ex-lurker
Sep 23, 2007
621
6
0
PA USA
www.roadstersandragtops.com
A noob wordpress question that is probably addressed somewhere in this forum even though I can't find it now. How do i set up different header images for each page like some cms systems do? For example: I have different 700x200 jpgs About_header, Privacy_header, Costs_header, Opt-in_header, Home_header, Links_header,etc.. I want home_header used by default. I am currently using MistyLook but don't mind changing themes around to make this work.

Thanks
ArtDeco
 


A noob wordpress question that is probably addressed somewhere in this forum even though I can't find it now. How do i set up different header images for each page like some cms systems do? For example: I have different 700x200 jpgs About_header, Privacy_header, Costs_header, Opt-in_header, Home_header, Links_header,etc.. I want home_header used by default. I am currently using MistyLook but don't mind changing themes around to make this work.

Thanks
ArtDeco

You can use conditional tags:

Code:
<?php
  if(is_single('5')) {
    //display header x
  } elseif(is_single('7')) { 
    //display header y
  } else { 
    //display header z
  } ?>
...with "5" and "7" being your post IDs. You can also add more elseifs in there.
 
Thanks. Looks easy enough, I'l try it. I'm surprised that it requires code at all. Seemed like something that should be in the control panel options someplace.

No problem, it should work fine this way. What would maybe be more convenient is only writing the image name in a variable with this loop. Or, even better, making it a switch function instead of if-else. Then simply call the variable in the img src tag, something like this:

Code:
<img src="<?php bloginfo('template_url'); ?>/img/headers/<?php echo $headerimg; ?>.jpg" 
  alt="<?php the_title(); ?>" />
What you could do to avoid coding in the future is use custom fields; the theme would have to be coded that way. You can then upload the header graphic for every post from within Wordpress and pass it as a custom field value, which the theme takes and displays as the header.

If you ever need a custom WP theme with that function - feel free hit me up :D
 
  • Like
Reactions: ArtDeco
Status
Not open for further replies.