Created
June 6, 2012 16:52
-
-
Save habibmac/2883235 to your computer and use it in GitHub Desktop.
WP: Conditional to check for hierarchy descendant
This file contains 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
// A conditional function to check if the current page is a descendant of the ID given to it. Useful for determining if a page is a grandchild, great-grandchild or father down the hierarchy tree. | |
function is_tree($pid) { // $pid = The ID of the page we're looking for pages underneath | |
global $post; // load details about this page | |
$anc = get_post_ancestors( $post->ID ); | |
foreach($anc as $ancestor) { | |
if(is_page() && $ancestor == $pid) { | |
return true; | |
} | |
} | |
if(is_page()&&(is_page($pid))) | |
return true; // we're at the page or at a sub page | |
else | |
return false; // we're elsewhere | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment