WordPress.org

Ready to get started?Download WordPress

Forums

Adding an alternate header (PHP question) (3 posts)

  1. Cold Iron Chef
    Member
    Posted 4 months ago #

    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!

  2. alchymyth
    The Sweeper & Moderator
    Posted 4 months ago #

    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

  3. Cold Iron Chef
    Member
    Posted 4 months ago #

    That worked! Thank you so much!!

Reply

You must log in to post.

About this Topic