Absolute Parent of Any Child Page


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.