Show child pages when on a child page

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;

Read More

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

Related posts

Leave a Reply

2 comments

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