List Child Pages in WordPress if you have any.

List Child Pages in WordPress if you have any.

<?php
/*
*		Get the Child pages if you have any.
*
*
*/
$children = get_pages('child_of='.$post->ID);
if( count( $children ) != 0 ) : ?>

<div class="list-sub-pages">
<?php 	
	$mypages = get_pages( array( 
	'child_of' => $post->ID, 
	'sort_column' => 'post_date', 
	'sort_order' => 'desc' 
	));
	
	foreach( $mypages as $page ) { ?>	
	<li><a href="<?php echo get_page_link( $page->ID ); ?>"><?php echo $page->post_title; ?></a></li>
	<?php } // end for each ?>
    </div><!-- list sub pages -->
<?php endif; ?>

 

Leave a Reply

Your email address will not be published. Required fields are marked *

− 7 = 3