Last active
May 30, 2016 10:55
-
-
Save amielucha/dcaac1dbde9e60289b0383ba661a437c to your computer and use it in GitHub Desktop.
WordPress is_tree()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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