Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Conditional checks for subpages
<?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