Want to be able to use one condition which includes or excludes pages based on weather they are children of a specific page?
Add this code to functions.php:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | function is_kid( $pid,$includeparent = 0 ) { // $pid = The ID of the page we're looking for pages underneath //$includeparent = 1 to include the parent page, 0 to exclude global $post; // load details about this page if ( is_page($pid) ) return $includeparent; // we're at the page $anc = get_post_ancestors( $post->ID ); foreach ( $anc as $ancestor ) { if( is_page() && $ancestor == $pid ) { return true; } } return false; // we aren't at the page, and the page is not an ancestor } |
then use this in your page template:
0 1 2 3 4 5 | if (is_kid($page_id,1)) //1 to include the parent page, 0 to exclude { code here } |