Show the child and grandchild page content in WordPress

I have a page structure like this in WordPress:

  • Main Page
    • Main page child
      • Main page grandchild
      • Main page grandchild
      • Main page grandchild
      • Main page grandchild
    • Main page child
      • Main page grandchild
      • Main page grandchild
      • Main page grandchild
      • Main page grandchild

etc…

Read More

I just want to show the title/content for each child page/grandchild page on the main page it’s self, please can anyone help?

Related posts

Leave a Reply

1 comment

  1. You should use wp_list_pages() function, and specify a top ancestor and level of 2.

    <?php 
    
      $postid = get_the_ID();
      $topid = get_top_ancestor($postid); 
    
      $args = array(
              'depth'        => 2,
              'show_date'    => '',
              'date_format'  => get_option('date_format'),
              'child_of'     => $topid,
              'exclude'      => '',
              'include'      => '',
              'title_li'     => '',
              'echo'         => 1,
              'authors'      => '',
              'sort_order'   => 'ASC',
              'link_before'  => '',
              'link_after'   => '',
              'walker'       => '',
              'post_type'    => 'page',
              'post_status'  => 'publish' 
      ); ?>
    <ul>
      <?php wp_list_pages( $args ); ?>
    </ul>