Display headers on static pages (6 posts)

  1. sanddlife
    Posted 6 years ago #

    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';}

    http://www.sanddsoft.com - just a staging dev area.


  2. esmi
    Forum Moderator
    Posted 6 years ago #

    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.

  3. sanddlife
    Posted 6 years ago #

    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="http://sanddsoft.com/images/"/>

    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?

  4. sanddlife
    Posted 6 years ago #

    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.

  5. Lweel8
    Posted 5 years ago #

    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.

  6. Lweel8
    Posted 5 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic