Top Level Page
- Second Level Page
--- Child Page
--- Child Page
--- Child Page

The goal here is to list all children of second level, I have that done from the codex. However, when I click on a Child, the children should still display because we're technically still inside of the Second Level.

// Globalize the $post variable;
// probably already available in this context, but just in case...
global $post;
    wp_list_pages( array(
        // Only pages that are children of the current page
        'child_of' => $post->ID,
        // Only show one level of hierarchy
        'depth' => 1
    ) );
  • Do you always want to show all children to the top level page, even grandchildren? OR do you only want to show the grandchildren when you're view the second level page?
    – Howdy_McGee
    Jan 30, 2015 at 17:57
  • I only want to show the grandchildren when im viewing the second level page.. Jan 30, 2015 at 18:03

1 Answer 1


Is this what you are after?

    if($post->post_parent) {
        // if $post has parent than it is "Second level" and show its children.
        $children = wp_list_pages("child_of=".$post->post_parent."&echo=0");
    } else {
        // else it's a "Top level" so display children & grand children? 
        $children = wp_list_pages("child_of=".$post->ID."&echo=0");

    if ($children) {
        echo "<ul>$children</ul>";

Source: http://codex.wordpress.org/Function_Reference/wp_list_pages#List_subpages_even_if_on_a_subpage

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.