sirk-c
9/29/2016 - 7:06 PM

Wordpress is_tree function

Wordpress is_tree function

// =============================================================================
// Tree function
// =============================================================================

/*----------  
USAGE - number is ID of page and will return true for that page and any child pages under it
if (is_tree(12)) {
    // do this
} elseif (is_tree(14)) {
    ....

----------*/

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()&&($post->post_parent==$pid||is_page($pid))) 
        return true;   // we're at the page or at a sub page
    else 
        return false;  // we're elsewhere
};