WordPress.org

Support

Support » Plugins and Hacks » Hacks » Adding an alternate header (PHP question)

Adding an alternate header (PHP question)

  • Hi,

    I am editing the Tempera theme to have an alternate header on certain pages. I have succeeded thus far in finding the bit of PHP that lets me control that (in header.php), and wrote a bit of code to successfully insert my own code on select pages. I’m not very good at PHP (I’m still learning). This is what I’ve got so far, this works, except for the homepage.

    <?php
    if (is_page(array('38', '344', '498', '26', '48', '491')))
    {
    echo '<h1 class="customheadertitle">Services Sociaux</h1><h2 class="customheadertagline">pour personnes âgées 50 ans+</h2>';
    }
    ?>
    <?php
    if (is_page(array('338', '54', '56')))
    {
    echo '<h1 class="customheadertitle">Programmes</h1><h2 class="customheadertagline">pour personnes âgées 50 ans+</h2>';
    }
    ?>
    <?php
    if (is_page(array('352', '360', '367')))
    {
    cryout_branding_hook();
    }
    ?>

    What I would like my code to do is this:

    If pages x,y,z etc… are being viewed, display Code A
    If pages u,v,w etc… are being viewed, display Code B
    If viewing any other page not listed above, then display default header ( cryout_branding_hook(); ).

    I can’t seem to get elseif statements to work for me, so I must be doing something wrong.

    What is the proper code for doing what I want?

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Michael

    @alchymyth

    Forum Moderator

    the home page could be checked with the conditional tag is_home() or is_front_page(); http://codex.wordpress.org/Conditional_Tags

    as for the if/elseif/else, try for example:

    <?php
    if (is_page(array('38', '344', '498', '26', '48', '491')))
    {
    echo '<h1 class="customheadertitle">Services Sociaux</h1><h2 class="customheadertagline">pour personnes âgées 50 ans+</h2>';
    }
    elseif (is_page(array('338', '54', '56')))
    {
    echo '<h1 class="customheadertitle">Programmes</h1><h2 class="customheadertagline">pour personnes âgées 50 ans+</h2>';
    }
    else
    {
    cryout_branding_hook();
    }
    ?>

    if you are referring to static pages only, change the last else to elseif( is_page() )

    also, don’t use quotes around the page ids; http://codex.wordpress.org/Conditional_Tags#A_PAGE_Page

    That worked! Thank you so much!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding an alternate header (PHP question)’ is closed to new replies.