navigation – wp_list_pages to show all pages on all sub pages

Question

I have this code to list my parent page and all pages under it on the sidebar. It shows both parent and child pages on first two levels but when I open a third level page, it only shows the current page on the sidebar. How can I modify this to show parent page and all child pages, no matter how many levels of child pages I have.

CODE:

<?php
        if ( $post->post_parent ) {
            $children = wp_list_pages( array(
                'title_li' => '',
                'depth'    => 0,
                'child_of' => $post->post_parent,
                'echo'     => 0
    
            ));
    } else {
        $children = wp_list_pages( array(
            'title_li' => '',
            
            'depth'        => 0,
            'child_of' => $post->ID,
            'echo'     => 0

        ) );
    }

    if ( $children ) : ?>
        <ul class="sideNavigation">
            <?php echo $children; ?>
        </ul>
    <?php endif; ?>

0
absolutelygradually 2 years 2021-03-24T02:12:26-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse