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.

On my site I have a number of parent pages with associated child pages. How can I show all the child pages of one particular parent when a visitor is either on the parent page or one of it's children?

For example;

If someone clicks onto the "Story" parent page, they'll see a list of "story" child pages in the sidebar (As well as a link to the parent page). Then if they click through to one of those child pages, they'll still be able to see the list in the sidebar

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted
    Add this code in sidebar.php.this code will help you.                    


                        global $post;
                        $parent_id  = $post->post_parent; 
                        if(!empty($parent_id)){
                        $parent_post=get_post($parent_id);
                        echo '<h1 class="entry-title">'.$parent_post->post_title.'</h1>';
                            echo '<ul>';
                            $children = wp_list_pages('title_li=&child_of=' . $parent_id . '&echo=0');
                            if ($children) {
                            echo $children;
                            echo '</ul>';
                            } 
                         } else { 
                        echo '<ul>';
                        $page =$post->ID;
                        $children = wp_list_pages('title_li=&child_of=' . $page . '&echo=0');
                            if ($children) { 
                            echo $children;
                            } 
                        echo '</ul>';
                        } 
share|improve this answer
    
Perfect! Thank you –  Dean Elliott Oct 9 '12 at 12:42
add comment

Depends on how you want to do it, but you can use the Sub Pages widget plugin

http://wordpress.org/extend/plugins/subpages-widget/

It hasn't been updated for a long while, but seems to be working fine on a 3.4.2 install of WP.

share|improve this answer
    
I can't really use a plugin (It's for a client) so it'd need to be hardcoded –  Dean Elliott Oct 9 '12 at 10:45
1  
Ok, well in a nutshell, you need to get the parent page of your current page ($page->page_parent) and then pass this ID to wp_list_pages() with the child_of parameter being the page_parent you found earlier. –  anu Oct 9 '12 at 10:52
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.