global $post; // if outside the loop
if ( is_page() && $post->post_parent ) {
// This is a subpage
} else {
// This is not a subpage
}
Eller
functions.php
function is_tree($pid) { // $pid = The ID of the page we're looking for pages underneath
global $post; // load details about this page
$anc = get_post_ancestors( $post->ID );
foreach($anc as $ancestor) {
if(is_page() && $ancestor == $pid) {
return true;
}
}
if(is_page() && (is_page($pid)))
return true; // we're at the page or at a sub page
else
return false; // we're elsewhere
};
if(is_tree('2')){ // 2 being the parent page id
// Do something if the parent page of the current page has the id of two
}