WordPress Side Navigation with Parent Heading and Child Sub Pages

Question

I have the following navigational structure in WordPress:

  Page
     Sub Page
        Child Page
        Child Page
        Child Page
  Page
     Sub Page
        Child Page
        Child Page
        Child Page
  Page
     Sub Page
        Child Page
        Child Page
        Child Page

On each Sub Page and Child Page, I want to display the following in the sidebar:

  Sub Page
        Child Page
        Child Page
        Child Page

The closest I’ve come to this is the following code from here:

<ul>
<?php
global $post;
$current_page_parent = ( $post->post_parent ? $post->post_parent : $post->ID );      
wp_list_pages( array(
       'title_li' => '',
       'child_of' => $current_page_parent,
       'depth' => '1' )
);
?>
</ul>

However, on Sub Pages it only shows a list of all Sub Pages (without Child Pages) and on Child Pages, it displays a list of Child Pages of that section but the parent Sub Page title is missing.

How do I modify to achieve what I’m looking for?

Thanks!

0
Troy Templeman 3 years 2020-06-11T03:10:33-05:00 0 Answers 94 views 0

Leave an answer

Browse
Browse