Skip to content

Instantly share code, notes, and snippets.

@jaredatch
Created September 21, 2012 23:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredatch/3764519 to your computer and use it in GitHub Desktop.
Save jaredatch/3764519 to your computer and use it in GitHub Desktop.
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