List Child Pages


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



Copy this code and paste it in your HTML
  1. <?php if ( is_page() ) { ?>
  2.  
  3. <?php
  4. if($post->post_parent)
  5. $children = wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0'); else
  6. $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
  7. if ($children) { ?>
  8.  
  9. <li>
  10. <h2>
  11. <?php
  12. $parent_title = get_the_title($post->post_parent);
  13. echo $parent_title;
  14. ?>
  15. </h2>
  16.  
  17. <ul>
  18. <?php echo $children; ?>
  19. </ul>
  20. </li>
  21.  
  22. <?php } } ?>

URL: http://www.tammyhartdesigns.com/tutorials/wordpress-how-to-list-child-pages-in-sidebar/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.