Guest User

Untitled

a guest
Jun 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. <?php
  2. $parents = get_post_ancestors($post);
  3. if(count($parents)>=2):
  4. //Page is a grandchild, show highest level parents as menu
  5. echo '<ul>';
  6. wp_list_pages('title_li=&child_of='.end($parents));
  7. echo '</ul>';
  8. elseif(count($parents)==1):
  9. //Page is a child
  10. echo '<ul>';
  11. wp_list_pages('title_li=&child_of='.$parents[0]);
  12. echo '</ul>';
  13. elseif(wp_list_pages("child_of=".$post->ID."&echo=0")): // page is top level and has children
  14. echo '<ul>';
  15. wp_list_pages('title_li=&child_of='.$post->ID);
  16. echo '</ul>';
  17. endif;
  18. ?>
Add Comment
Please, Sign In to add comment