• Hi,

    I am working on a theme and I am stuck on the menu. The website has several child pages and those pages have children. What I want to achieve is when you click on a child page, it displays a menu with the child page and its children only.

    Home
    About
    Events
    -Event 1
    -Event 2
    –Venue
    –Food
    –Music
    -Event 3
    Contact

    What I want is when I click on Event 2, It displays Event 2 and its children only.

    My current solution displays all the child pages i.e. Event 1, Event 3. Please find my code below.

    <?php
    // find parent of current page
    if ($post->post_parent) {
        $ancestors = get_post_ancestors($post->ID);
        $parent = $ancestors[count($ancestors) - 1];
    } else {
        $parent = $post->ID;
    }
    
    $children = wp_list_pages("title_li=&depth=2&child_of=" . $parent . "&echo=0");
    
    if ($children) { ?>
    
        <ul class="list-children">
            <?php echo $children; ?>
        </ul>
    
    <?php } ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Display a child page and its children only.’ is closed to new replies.