Conditional check if page is parent or child in WordPress
Author: Aleš Sýkora, 14. 1. 2021
If you need to display something only if post has childs (or not), you can use this conditional in your code.
<?php
$args = array(
'post_parent' => get_the_ID(), // Current post's ID
);
$children = get_children( $args );
// Check if the post has any child
if ( ! empty($children) ) {
// The post has at least one child
echo "has childs";
} else {
// There is no child for this post
echo "do not have childs";
}
?>