Be seen. Boost your question’s priority for more expert views and faster solutions
<?php
$allPages = wp_list_pages();
if ($allPages) {
foreach($allPages as $onePage) {
if(!$post->post_parent){
// will display the subpages of this top level page
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
} else {
// diplays only the subpages of parent level
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
}
if($post->ancestors) {
// now you can get the the top ID of this page
// wp is putting the ids DESC, thats why the top level ID is the last one
$ancestors = end($post->ancestors);
$children = wp_list_pages("title_li=&child_of=".$ancestors."&echo=0");
// you will always get the whole subpages list
}
if ($children) {
echo '<ul><li>';
echo $children;
echo '</li></ul>';
}
}
}
?>
<?php
if($post->post_parent)
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
if ($children) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
"I do not want to use a plug-in or the dashboard."
Why do you not want to use the built-in Custom Menus? It vastly simplifies the process of creating and maintaining navigation?