Show title only if content

108 views Asked by At

I want to hide <h2>title</h2> if they are not children pages.

<h2> title</h2></br>

<?php
// Globalize the $post variable;
// probably already available in this context, but just in case...
global $post;

wp_list_pages( array(
        'title_li'     => __(''), 
    // Only pages that are children of the current page
    'child_of' => $post->ID,
    // Only show one level of hierarchy
    'depth' => 1,
) );
?>
1

There are 1 answers

0
André On

You can use the get_children function to get all child contents of your post. If the return array is empty, there are no child pages defined:

<?php
   $children =& get_children( 'post_type=page' );
   if (!empty($children)) "<h2> title</h2>";
?>

Documentation: