Add this to your function.php file:
function hierarchical_submenu_get_children($post, $current_page) {
$menu = null;
// Get all immediate children of this page
$children = get_pages('child_of=" . $post->ID . "&parent=" . $post->ID . "&sort_column=menu_order&sort_order=ASC');
if ($children) {
$menu = "\n<ul>\n";
foreach ($children as $child) {
// If the child is the viewed page or one of its ancestors, highlight it
if (in_array($child->ID, get_post_ancestors($current_page)) || ($child->ID == $current_page->ID)) {
$menu .= '<li class="sub-menu"><a href="' . get_permalink($child) . '" class="sub-menu current-item">' . $child->post_title . '</a>';
} else {
$menu .= '<li><a href="' . get_permalink($child) . '">' . $child->post_title . '</a>';
}
// If the page has children and is the viewed page or one of its ancestors, get its children
if (get_children($child->ID) && (in_array($child->ID, get_post_ancestors($current_page)) || ($child->ID == $current_page->ID))) {
$menu .= hierarchical_submenu_get_children($child, $current_page);
}
$menu .= "</li>\n";
}
$menu .= "</ul>\n";
}
return $menu;
}
Call in your sidebar like so:
<?php echo hierarchical_submenu($post); ?>