List WordPress subpages even if on a subpage

/ Published in: PHP
Save to your folder(s)

his code will show the child pages, and only the child pages, when on a parent or on one of the children.
This code will not work if placed after a widget block in the sidebar.

Copy this code and paste it in your HTML
  1. <?php
  2. if($post->post_parent)
  3. $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
  4. else
  5. $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
  6. if ($children) { ?>
  7. <ul>
  8. <?php echo $children; ?>
  9. </ul>
  10. <?php } ?>


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.