Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * is_tree()
- *
- * @url http://codex.wordpress.org/Conditional_Tags#Testing_for_sub-Pages
- */
- if ( !function_exists ( 'is_tree' ) ) {
- function is_tree( $pid ) { // $pid = The ID of the page we're looking for pages underneath
- // check only pages
- if (!is_page() )
- return false;
- // load details about this page
- global $post;
- // if a string is passed, get that page's id by path
- if ( is_string( $pid ) )
- $pid = get_page_by_path( $pid )->ID;
- // we're at the page or at a sub page
- if ( is_page( $pid ) )
- return true;
- // get all of the page's ancestors
- $anc = get_post_ancestors( $post->ID );
- // loop 'em
- foreach ( $anc as $ancestor ) {
- // untill finding the one that matches
- if( is_page() && $ancestor == $pid ) {
- return true;
- }
- }
- // we arn't at the page, and the page is not an ancestor
- return false;
- }
- }
- /**
- * Checks whether current page is a subpage or a top-level page
- *
- * @url http://codex.wordpress.org/Conditional_Tags#Testing_for_sub-Pages
- */
- if ( !function_exists ( 'is_subpage' ) ) {
- function is_subpage() {
- // load details about this page
- global $post;
- // test to see if the page has a parent
- if ( is_page() && $post->post_parent ) {
- // the ID of the parent is this
- $parentID = $post->post_parent;
- // return the ID
- return $parentID;
- // there is no parent so...
- } else {
- // ...the answer to the question is false
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment