Created
September 21, 2012 23:36
-
-
Save jaredatch/3764519 to your computer and use it in GitHub Desktop.
Conditional checks for subpages
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 | |
/** | |
* Checks for sub pages | |
* | |
* This see if the current page is the page, or is a sub page | |
* of the page | |
* | |
* @since 1.0.0 | |
* @link http://codex.wordpress.org/Conditional_Tags#Testing_for_sub-Pages | |
* @param int $pid, post id | |
* @return boolean | |
*/ | |
function is_tree( $pid ) { | |
global $post; | |
if ( is_page( $pid ) ) | |
return true; | |
$anc = get_post_ancestors( $post->ID ); | |
foreach ( $anc as $ancestor ) { | |
if ( is_page() && $ancestor == $pid ) { | |
return true; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment