Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 } ?>
share|improve this question
    
As near as I can tell the code I gave you earlier today does what you describe. How is the behavior of that code different from what you want to achieve here? –  s_ha_dum May 18 '13 at 19:43
    
may be you find your solution here wordpress.stackexchange.com/questions/98913/… –  Ravs May 18 '13 at 20:11
add comment

1 Answer

up vote 2 down vote accepted
<?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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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