Skip to content

Instantly share code, notes, and snippets.

@amielucha
Last active May 30, 2016 10:55
Show Gist options
  • Select an option

  • Save amielucha/dcaac1dbde9e60289b0383ba661a437c to your computer and use it in GitHub Desktop.

Select an option

Save amielucha/dcaac1dbde9e60289b0383ba661a437c to your computer and use it in GitHub Desktop.
WordPress is_tree()
<?php
//usage: place in functions.php
// has a certain page in ID
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 ) || get_topmost_parent( $post->ID ) == $pid ) ) return true;
else return false; // we're elsewhere
}
function get_topmost_parent( $post_id ){
$parent_id = get_post( $post_id )->post_parent;
if( $parent_id == 0 ){
return $post_id;
} else {
return get_topmost_parent( $parent_id );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment