动态wordpress侧边栏

I am trying to implement a sidebar in my wordpress website, it is currently static but I want it to be dynamic.

What I want exactly is for the page to check 'on page load' whether that particular page has sub-pages or not. If yes then it should display a sidebar on the right showing all sub pages under the current page.

I can implement this in normal PHP. but, I don't know how to do in wordpress.

I am new to wordpress. so ,I really do not know how to go about this.

This is the sidebar I want to display:

<div class="sidebar">
  <h2>In This Section</h2>
  <ul>
    <li style="list-style:none"><h3><a href="#">Sub Page 1</a></h3></li>
    <li style="list-style:none"><h3><a href="#">Sub Page 2</a></h3></li>
    <li style="list-style:none"><h3><a href="#">Sub Page 3</a></h3></li>
  </ul>
  <br />
</div>

The function you are looking for is wp_list_pages.

The page even has a whole section on Listing sub pages.

<?php
add_Action('init','any_name'); // call any_name function on initialize 
function any_name(){
global $post;     // if outside the loop

if ( is_page() && $post->post_parent ) {
    // This is a subpage

} else {
    // This is not a subpage you can do here whatever you want 
    // get sidebar
    get_sidebar(); // this will include sidebar.php
     // or something specific 

     get_sidebar('custom'); // this will include sidebar-custom.php
}

} ?>