function get_taxonomy_hierarchy($taxonomy, $parent = 0)
{
    // only 1 taxonomy
    $taxonomy = is_array($taxonomy) ? array_shift($taxonomy) : $taxonomy;
    // get all direct decendents of the $parent
    $terms = get_terms($taxonomy, array('parent' => $parent));
    // prepare a new array.  these are the children of $parent
    // we'll ultimately copy all the $terms into this new array, but only after they
    // find their own children
    $children = array();
    // go through all the direct decendents of $parent, and gather their children
    foreach ($terms as $term) {
        // recurse to get the direct decendents of "this" term
        $term->children = get_taxonomy_hierarchy($taxonomy, $term->term_id);
        // add the term to our new array
        $children[$term->term_id] = $term;
    }
    // send the results back to the caller
    return $children;
}
 public function widget($args, $instance)
 {
     $title = apply_filters('widget_title', $instance['title']);
     echo $args['before_widget'];
     $programs = get_taxonomy_hierarchy('program_category');
     $programs_html = '<div class="kst-finance-cont">';
     if (!empty($title)) {
         $programs_html .= '<h4>' . $title . '</h4>';
     }
     foreach ($programs as $program) {
         $programs_html .= '<ul class="kst-finance-programs">';
         $programs_html .= '<li><a href="' . get_term_link($program) . '" title="' . sprintf(__('View all post filed under %s', 'mortgagehouse'), $program->name) . '">' . $program->name . '</a></li>';
         $programs_html .= '<ul>';
         foreach ($program->children as $child) {
             $programs_html .= '<li><a href="' . get_term_link($child) . '" title="' . sprintf(__('View all post filed under %s', 'mortgagehouse'), $child->name) . '">' . $child->name . '</a></li>';
         }
         $programs_html .= '</ul>';
         $programs_html .= '</ul>';
     }
     echo $programs_html . '</div>';
     echo $args['after_widget'];
 }