WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

    if ( is_page('189') ) :
    elseif ( is_page() && !is_page(array('189','24','36',is_tree('24'),is_tree('36'))) ) :
    elseif ( is_page('24') && !is_page(array('36')) || is_tree('24') || is_or_descendant_tax('6','product_category') || is_or_descendant_tax('6','topic') ) :
    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') ) :
    elseif ( is_post_type_archive('download_type') ) :
share|improve this question

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

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

Your Answer


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.