Show child pages in sidebar based off of top level parent (code included) (1 post)

  1. adam533
    Posted 3 years ago #


    I am trying to show the child pages in the sidebar of a page based off the top level parent page. It should only show the first level of child pages and if there are none, then nothing will appear.

    I am using the following code right now, and it works for the most part. The one issue I am having (and am unable to solve myself) is to have it show just the first level of child pages based off the top level parent. This code does not do that as is. Instead if I were to be on a page that is two levels deep, then it shows that level of pages in the sidebar.

    How can I update this so it always shows the first level of child pages based off of the top level parent page?


          $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
          $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
          if ($children) { ?>
    		<li class="widget">
            	<h2 class="widgettitle">
                    $parent_title = get_the_title($post->post_parent);
                    echo $parent_title;
          <?php echo $children; ?>
          <?php } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.