WordPress get all subpages of current page’s parent page

Following code will display all the subpages of same parent page. also displays the subpages of current page if it is not a subpage.

<?php
  if($post->post_parent) {
  $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0$sort_column=menu_order");
  $title_heading = get_the_title($post->post_parent);
  }

  else {
  $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
  $title_heading = get_the_title($post->ID);
  }
  if ($children) { ?>

  <h2> <? echo $title_heading ?> </h2>
  <ul>
  <?php echo $children; ?>
  </ul>

<?php } ?>

3 thoughts on “WordPress get all subpages of current page’s parent page

Leave a Reply

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