In functions.php de functie om te checken

function has_children($post_ID = null) {
    if ($post_ID === null) {
        global $post;
        $post_ID = $post->ID;
    }
    $query = new WP_Query(array('post_parent' => $post_ID, 'post_type' => 'any'));

    return $query->have_posts();
}

Vervolgens in het thema de code om de subpagina’s te laten zien indien deze er zijn:

<?php if(has_children()):
						$headingtitle = get_the_title($post->post_parent);
					 ?>
					 <ul class="sbmnu">
					 <h3><a href="<?php the_permalink($headingid);?>"><?php echo $headingtitle;?></a></h3>
					 <?php
					 if($post->post_parent) { ?>
				      <?php $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0$sort_column=menu_order");
				      } else {
				      $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
				      };?>
				      <?php echo $children; wp_reset_query();?>
					  </ul>
					 <?php endif; ?>

 

Geef een reactie 0