Conditional for is page and page’s Children

In the functions file…

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()&&($post->post_parent==$pid||is_page($pid))) 
               return true;   // we're at the page or at a sub page
	else 
               return false;  // we're elsewhere
};

In the theme…

if (is_tree(8)) { //the number being the page ID
   // do stuff
}

Leave a Reply

Your email address will not be published. Required fields are marked *

+ 12 = 13