0

Below is the best code I could find for producing a list of subpages and the parent page. However, it only shows the parent page while on the subpages. How do I get this to display the parent page when the user is on the parent page also?

<?php
if($post->post_parent){
    $children = wp_list_pages("title_li=&include=".$post->post_parent."&echo=0"); 
    $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) { ?>
    <ul class="subpages">
        <?php echo $children; ?>
    </ul>
<?php } ?>
2
2
<?php
 if($post->post_parent){
    $children = wp_list_pages("title_li=&include=".$post->post_parent."&echo=0"); 
    $children .= wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
 } else {
    $children = wp_list_pages("title_li=&include=".$post->ID."&echo=0");
    $children .= wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
 }

 if ($children) { ?>
   <ul class="subpages">
     <?php echo $children; ?>
   </ul>
 <?php } ?>

Try that. Just have to include the parent much like you do on the child pages, but using the current $post-ID.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.