Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $parents = get_post_ancestors($post);
- if(count($parents)>=2):
- //Page is a grandchild, show highest level parents as menu
- echo '<ul>';
- wp_list_pages('title_li=&child_of='.end($parents));
- echo '</ul>';
- elseif(count($parents)==1):
- //Page is a child
- echo '<ul>';
- wp_list_pages('title_li=&child_of='.$parents[0]);
- echo '</ul>';
- elseif(wp_list_pages("child_of=".$post->ID."&echo=0")): // page is top level and has children
- echo '<ul>';
- wp_list_pages('title_li=&child_of='.$post->ID);
- echo '</ul>';
- endif;
- ?>
Add Comment
Please, Sign In to add comment