• Hi,
    I am currently using this if statement to change the headers of each page I use.

    <?php
    if (is_page('Home'))
    {
    	include(TEMPLATEPATH.'/header-col3.php');
    }
    elseif (is_page('Booking Procedure'))
    {
    	include(TEMPLATEPATH.'/header-col3.php');
    }
    elseif (is_page('Contact Us'))
    {
    	include(TEMPLATEPATH.'/header-col3.php');
    }
    else {include(TEMPLATEPATH.'/header-main.php');}
    ?>

    But all of them only have a different header picture, how can I use php to change the picture if it is “home” page or a “contact” page???

Viewing 1 replies (of 1 total)
  • Two ways you can do it. Pick one

    1) Put an IF statement inside of header-col3.php to display different images based on the page that is displaying,

    inside /header-col3.php will be an IMG tag with the header image
    <img src=" a file path is here " alt=" something " />

    change to

    <?php if ( is_page('Home') { ?>
       <img src="   home header file path goes here  "  alt=" something " />
    <?php } elseif (is_page('Booking Procedure')){ ?>
       <img src="   default file path goes here  "  alt=" something " />
    <?php } elseif (is_page('Contact Us')){ ?>
       <img src="   contact header file path goes here  "  alt=" something " />
    <?php } ?>

    2) OR, another approach, make different template files for Home and Contact.
    for example, /header-col3-home.php and /header-col3-contact.php

    To do this copy /header-col3.php to the other two filenames.

    Then change /header-col3-home.php and /header-col3-contact.php to display the image you want. Your PHP would look like this:

    <?php
    if (is_page('Home'))
    {
    	include(TEMPLATEPATH.'/header-col3-home.php');
    }
    elseif (is_page('Booking Procedure'))
    {
    	include(TEMPLATEPATH.'/header-col3.php');
    }
    elseif (is_page('Contact Us'))
    {
    	include(TEMPLATEPATH.'/header-col3-contact.php');
    }
    else {include(TEMPLATEPATH.'/header-main.php');}
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Using IF statement on is_page to change images’ is closed to new replies.