Created
September 27, 2010 05:55
-
-
Save brendannee/598672 to your computer and use it in GitHub Desktop.
List top level pages in Wordpress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment