I am trying to produce a simple function to perform a "status test". Goal would be to test if the current page being seen has any child pages or otherwise. By using this to change layout to accomodate child pages. The next code appears enjoy it should work, but alas, no dice.

Anybody see what I am missing? EDIT- Observe that this really is in WordPress.

function is_subpage() {
global $post;                              // load details about this page

if ( is_page() && $post->post_parent ) {   // test to see if the page has a parent
    return true;                                            // return true, confirming there is a parent

} else {                                   // there is no parent so ...
    return false;                          // ... the answer to the question is false

Because it appears a little assets intensive to load all of the child pages simply to perform a simple check, I figured of the early today:

function has_children($p = null) {
    global $post, $wpdb;
    $pid = ($p) ? $p : $post->post_parent;

    if ($pid) :
        $r = $wpdb->get_row("SELECT ID FROM $wpdb->posts WHERE post_parent = $pid LIMIT 1");
        if ($r) : return true; endif;
    else :
        return false;

Technology-not only just like if (has_children()) or pass it the publish parent if (has_children($publish-publish_parent)) — the second is useful if you are using get_posts/get_pages and never the worldwide $publish variable.