Show child pages in sidebar based off of top level parent (code included)
-
Hello,
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?
Thanks!
<?php if($post->post_parent) $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0"); if ($children) { ?> <li class="widget"> <h2 class="widgettitle"> <?php $parent_title = get_the_title($post->post_parent); echo $parent_title; ?> </h2> <ul> <?php echo $children; ?> </ul> </li> <?php } ?>
- The topic ‘Show child pages in sidebar based off of top level parent (code included)’ is closed to new replies.