WordPress.org

Ready to get started?Download WordPress

Forums

Headers with different banners for different pages; a code question. (4 posts)

  1. ebedgert
    Member
    Posted 4 years ago #

    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?

  2. esmi
    Forum Moderator
    Posted 4 years ago #

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

  3. alchymyth
    Forum Moderator
    Posted 4 years ago #

    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

  4. ebedgert
    Member
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.