Show content if parent page has children

I ended up using this code:

<?php
global $post;
$children = get_pages( array( 'child_of' => $post->ID ) );

if ( is_page() && $post->post_parent ) : ?>
This is a child-page.

<?php elseif ( is_page() && count( $children ) > 0 ) : ?>
This is a parent-page (with one or more children)

<?php else : ?>
This is a parent page without children.

<?php endif; ?>

Leave a Comment