Posted By

madnil on 01/05/12


Tagged

wordpress


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

100tral


Absolute Parent of Any Child Page


 / Published in: PHP
 

  1. function is_tree($pid) { // $pid = The ID of the page we're looking for pages underneath
  2. global $post; // load details about this page
  3.  
  4. if ( is_page($pid) )
  5. return true; // we're at the page or at a sub page
  6.  
  7. $anc = get_post_ancestors( $post->ID );
  8. foreach ( $anc as $ancestor ) {
  9. if( is_page() && $ancestor == $pid ) {
  10. return true;
  11. }
  12. }
  13. return false; // we aren't at the page, and the page is not an ancestor
  14. }

Report this snippet  

You need to login to post a comment.