wordpress display child pages on parent page template code example

Example: wordpress grand child list page names

<?php //get first level child pages 
		$mypages = get_pages( array( 
		'child_of' => $post->ID, 
		'sort_column' => 'menu_order',
		'parent' => $post->ID ) );
	  	foreach( $mypages as $page ) {
	  		$mycontent = $page->post_content;
		 	$mycontent = apply_filters( 'the_content', $mycontent );
 		?>
<!--if has children, add div in the parent section for each child otherwise no div -->
<?php
      $childArgs = array(
          'sort_order' => 'ASC',
          'sort_column' => 'menu_order',
          'child_of' => $page->ID
      );
      $childList = get_pages($childArgs);
      foreach ($childList as $child) { ?>
        <div class="grandchild-page">
        <h2><a href="<?php echo get_page_link( $child->ID ); ?>"><?php echo $child->post_title; ?></a></h2>
        </div>  
    <?php } ?><!--end grandchildren-->
<?php } ?>
<?php endwhile;  
   endif; ?>

Tags:

Php Example