Support » Fixing WordPress » Display headers on static pages

  • I’d like to display graphic headers on specific pages and wonder if this is the code to use.

    I’d rather use the page_id, but I can’t seem to find the pageid for each of my pages. How to??

    if (is_page('home') ) {
    $hdrimg = 'homepage.jpg';
    } elseif ( is_page('blog') ) {
    $hdrimg = 'blogpage.jpg';} – just a staging dev area.


Viewing 5 replies - 1 through 5 (of 5 total)
  • esmi


    Forum Moderator

    The code looks fine and you could just substitute page ids for the page titles.

    You can find the individual page ids within the Admin/Pages. Place your cursor over a page title and look the url being displayed in the bottom left of your browser. It should end with &post=xxx. That xxx number is the page id.

    I put the following code in my page.php page.

    <?php if (is_page('21') ) {
    	$hdrimg = 'header-home.jpg';
    } elseif ( is_page('26') ) {
    	$hdrimg = 'header-blog.jpg';
    } elseif ( is_page('3') ) {
    	$hdrimg = 'header-photos.jpg';
    } elseif ( is_page('30') ) {
    	$hdrimg = 'header-schedule.jpg';
    } elseif ( is_page('32') ) {
    	$hdrimg = 'header-records.jpg';
    } elseif ( is_page('34') ) {
    	$hdrimg = 'header-coaches.jpg';
    } elseif ( is_page('36') ) {
    	$hdrimg = 'header-boosterclub.jpg';
    } elseif ( is_page('38') ) {
    	$hdrimg = 'header-contactus.jpg';
    } ?>

    Using Firebug, it shows the the code below but the variable $hdrimg value is missing.
    <img src=""/>

    Either I’m using the wrong page id’s or my links in the sliding header image links are not correct and perhaps I should link to the page ids.

    Make sense?

    My bad. Syntax error in this line.

    <img src="<?php bloginfo('url');?>/images/<?php echo $hdrimg;?>"/>

    I left out the ‘echo’ command. Oops. 😉

    Works like a charm…almost.

    Even though the ‘blog’ page is a page, it doesn’t seem to recognize that as a page in my if statements.

    I’m having the same issue, where is_page isn’t working for my blog page. I would guess it is because it is not a page anymore and is instead now a ‘special’ page like front_page.

    Turns out that is_home functions as is_blog when you have identified a static page to be the page where posts are displayed. So just use is_home.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Display headers on static pages’ is closed to new replies.