2

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

2 Answers 2

1
    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>';
                        } 
0
0

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.

2
  • I can't really use a plugin (It's for a client) so it'd need to be hardcoded Oct 9, 2012 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, 2012 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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