Conditional for determing child pages not working
-
I’m using this code below on a new site (src is WordPress – see link below). I’ve used it before and it’s worked fine. For some reason it’s not working now for child pages – works for the parent though. The script simply adds a header for the section and all of the pages under it. I feel like I’m missing something obvious. And yes I did assign the children to the correct parent page.
Sample: http://www.greenmountainsoftware.com/wp/about-us/ View any of the children of About Us.
function is_tree( $pid ) { // $pid = The ID of the page we're looking for pages underneath global $post; // load details about this page if ( is_page($pid) ) return true; // we're at the page or at a sub page $anc = get_post_ancestors( $post->ID ); foreach ( $anc as $ancestor ) { if( is_page() && $ancestor == $pid ) { return true; } } return false; // we arn't at the page, and the page is not an ancestor } if (is_tree('2')) { ?> <div id="artwork"><img src="<?php echo THESIS_CUSTOM_FOLDER; ?>/images/about-us-head.jpg" width="980" height="89" alt="About Green Mountain Software" /><img src="<?php echo THESIS_CUSTOM_FOLDER; ?>/images/fadestrip.jpg" width="980" height="18" alt="Green Mountain Software" /></div> <?php }Code Source: http://codex.wordpress.org/Conditional_Tags#Testing_for_sub-Pages
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
The topic ‘Conditional for determing child pages not working’ is closed to new replies.