Guest User

Untitled

a guest
Jun 20th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. <?php
  2. if(!$post->post_parent){
  3. // will display the subpages of this top level page
  4. $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
  5. }else{
  6. // diplays only the subpages of parent level
  7. //$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
  8.  
  9. if($post->ancestors)
  10. {
  11. // now you can get the the top ID of this page
  12. // wp is putting the ids DESC, thats why the top level ID is the last one
  13. $ancestors = end($post->ancestors);
  14. $children = wp_list_pages("title_li=&child_of=".$ancestors."&echo=0");
  15. // you will always get the whole subpages list
  16. }
  17. }
  18.  
  19. if ($children) { ?>
  20. <ul>
  21. <?php echo $children; ?>
  22. </ul>
  23. <?php } ?>
Add Comment
Please, Sign In to add comment