List Pages in Sidebar, Exclude Current Page


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

Based on code via Tammy Hart - slight modification to exclude current page.


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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.