2

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.

<?php
// 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 '15 at 17:57
  • I only want to show the grandchildren when im viewing the second level page.. – edwardhimes Jan 30 '15 at 18:03
0

Is this what you are after?

<?php
    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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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