Last active
March 1, 2021 20:57
-
-
Save intelliweb/5255966 to your computer and use it in GitHub Desktop.
WP: is_tree() function to check if the current page is the page or a sub page of the page ID specified. Can be used as conditional tag with Widget Logic. Source: http://codex.wordpress.org/Conditional_Tags#A_PAGE_Page
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 | |
// This function will return true if we are looking at the page in question or one of its sub pages | |
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($pid) ) | |
return TRUE; // we're at the page or at a sub page | |
$anc = get_post_ancestors( $post->ID ); | |
foreach ( $anc as $ancestor ) { | |
if( is_page() && $ancestor == $pid ) { | |
return TRUE; | |
} | |
} | |
return FALSE; // we aren't at the page, and the page is not an ancestor | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment