Created
August 13, 2013 20:54
-
-
Save brycejacobson/6225573 to your computer and use it in GitHub Desktop.
WordPress is_tree function to see if a page is an ancestor.
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
<?php | |
//* Do NOT include the opening php tag | |
//* Determin if a page is an ancestor | |
function is_tree($pid) // $pid = The ID of the page we're looking for pages underneath | |
{ | |
global $post; // load details about this page | |
$ancestors = get_post_ancestors($post->$pid); | |
$root = count($ancestors) - 1; | |
$parent = $ancestors[$root]; | |
if(is_page() && (is_page($pid) || $post->post_parent == $pid || in_array($pid, $ancestors))) | |
{ | |
return true; // we're at the page or at a sub page | |
} | |
else | |
{ | |
return false; // we're elsewhere | |
} | |
}; |
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
<?php | |
//* Do NOT include the opening php tag | |
if (is_tree(2)) // 2 is the id of the page we are looking under | |
{ | |
// stuff | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment