WordPress Function to is_tree() conditional Function

is_tree() conditional Function

/* Adapted from csstricks with addition of
ancestors .... use = if(is_tree($id)) { // do stuff } ... Returns true if the
page is  = $id OR any of it's children OR descendants */

function is_tree($pid) {      // $pid = The ID of the page we're looking for pages underneath
  global $post;         // load details about this page
  $ancestors = get_post_ancestors($post);
  if(is_page()&&($post->post_parent==$pid||is_page($pid)||(in_array($pid,$ancestors))))
    return true;   // we're at the page or at a sub page
  else
    return false;  // we're elsewhere 
  };

You may also like...

Leave a Reply

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