Support » Themes and Templates » Headers with different banners for different pages; a code question.

  • I’ve been able to successfully use an alternate banner for specific pages on my site, using the following code:

    if (is_page('5436')){
    
    	include(TEMPLATEPATH.'/header-alternate.php'); 
    
    }
    
    else {
    
    	include(TEMPLATEPATH.'/headerdefault.php');

    etc.

    However, when I try to use an elseif statement so that I can use a third banner for specific pages, it messes up the header (and hence the whole site). The code I’m trying to use is (example):

    if (is_page('5436')){
    
    	include(TEMPLATEPATH.'/header-alternate.php'); 
    
    }
    
    elseif (is_page('5450','5508')){
    
    	include(TEMPLATEPATH.'/header-alternate2.php'); 
    
    }
    
    else {
    
    	include(TEMPLATEPATH.'/headerdefault.php');

    Am I doing something wrong? All the necessary files are located in the right place. Why does it work OK with the first example, but not the second?

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

    (@esmi)

    Forum Moderator

    There’s an easier way to achieve this using the body_class().

    Michael

    (@alchymyth)

    Forum Moderator

    are you sure that is_page() takes multiple arguments the way you tried?

    try:
    is_page(array(42,'about-me','About Me And Joe'))
    http://codex.wordpress.org/Conditional_Tags#A_PAGE_Page

    Alchymth – Thank you. That did the trick. Should have read the codex closer. (It’s worth noting also to pay attention that page numbers do NOT need to be enclosed in quotes when using array).

    Esmi, thanks for the tip but unfortunately I don’t have time to root through the theme files making new changes. I am just hoping to build on what already works. I will keep that in mind for the future though.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Headers with different banners for different pages; a code question.’ is closed to new replies.