Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've been pulling my hair out today trying to get this right. Basically I have a sidebar, which makes requests to individual files (such as sidebar-home.php, sidebar-residential.php) and different dynamic menus are supposed to be loaded depending on what page you're on.

Previously this has been easy to set up when moving between: is_page, is_single, is_category, is_archive etc... But, as I have read, is_page keeps returning as true, despite any reset or endif condition.

Would love to hear some feedback on what I am doing wrong here. How can I get is_page(24) and is_page(36) to see different parts of the sidebar?

Code is below

<?php
    if ( is_page('189') ) :
        get_sidebar('home');   
    elseif ( is_page() && !is_page(array('189','24','36',is_tree('24'),is_tree('36'))) ) :
        get_sidebar('page');
    elseif ( is_page('24') && !is_page(array('36')) || is_tree('24') || is_or_descendant_tax('6','product_category') || is_or_descendant_tax('6','topic') ) :
        get_sidebar('residential');
    elseif ( is_page(array('36'))  && !is_page(array('24')) || is_tree('36') || is_or_descendant_tax('15','product_category') || is_or_descendant_tax('5','topic') ) :
        get_sidebar('utility');
    elseif ( is_post_type_archive('download_type') ) :
        get_sidebar('download');
    endif;
?>
share|improve this question
add comment

2 Answers

is_tree returns true or false, passing false to is_page will always return true. I don't think this does what you expect it to:

!is_page( array('189','24','36',is_tree('24'),is_tree('36')) )
share|improve this answer
add comment

Part of the issue was the custom is_tree function (provided by CSS Tricks), combined with conditional tags stacking on top of each other and following tags to always return return.

My working code is below, will provide a further explanation of how it works if enough people request (sorry for all the additional php opening/closing tags in advance).

<?php if (is_front_page()) {   ?> 

<?php get_sidebar('home'); ?>  

<?php } if ( get_post_type() == 'downloads' ){ ?> 

<?php get_sidebar('download'); ?>   

<?php } if ( is_page('24') || $post->post_parent == '24' || is_or_descendant_tax('6','product_category') || is_or_descendant_tax('6','topic')) {   ?> 

<?php get_sidebar('residential'); ?>        

<?php } elseif ( is_page('36') || $post->post_parent == '36' || is_or_descendant_tax('15','product_category') || is_or_descendant_tax('5','topic')) {  ?> 

<?php get_sidebar('utility'); ?> 

<?php }  if (!(is_page(array('24','36')) || is_front_page() || $post->post_parent == '24' || $post->post_parent == '36' || is_or_descendant_tax('15','product_category') || is_or_descendant_tax('5','topic') || is_or_descendant_tax('6','product_category') || is_or_descendant_tax('6','topic') || is_archive('download_type'))) { ?> 

<?php get_sidebar('page'); ?>  

<?php } ?> 
share|improve this answer
    
I'm afraid it isn't very helpful, unless you publish how does is_or_descendant_tax function look like. –  Krzysiek Dróżdż Dec 5 '13 at 9:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.