function widget($args, $instance)
    {
        extract($args, EXTR_SKIP);
        $instance = wp_parse_args($instance, $this->defaults);
        $title = apply_filters('widget_title', $instance['title']);
        $valid_sort_orders = array('count', 'name', 'id', 'slug');
        if (in_array($instance['sort_by'], $valid_sort_orders)) {
            $sort_by = $instance['sort_by'];
            $sort_order = (bool) $instance['asc_sort_order'] ? 'ASC' : 'DESC';
        } else {
            // by default, display alphabetically
            $sort_by = 'name';
            $sort_order = 'DESC';
        }
        $only_top_level = (bool) $instance['only_top_level'] ? 0 : '';
        $hide_empty = (bool) $instance['hide_empty'] ? 1 : 0;
        $disp_article_count = (bool) $instance['disp_article_count'] ? 1 : 0;
        $num = empty($instance['num']) ? 5 : (int) $instance['num'];
        /* Before widget (defined by themes). */
        echo $before_widget;
        /* Display Widget */
        ?>
 
	        <?php 
        /* Display the widget title if one was input (before and after defined by themes). */
        if ($title) {
            echo $before_title . $title . $after_title;
        }
        ?>
	                            
	                <?php 
        $args = array('hide_empty' => $hide_empty, 'number' => $num, 'child_of' => 0, 'pad_counts' => 1, 'hierarchical' => 1, 'parent' => $only_top_level, 'orderby' => $sort_by, 'order' => $sort_order);
        $categories = get_terms('ht_kb_category', $args);
        echo '<ul class="hkb_category_widget__category_list">';
        foreach ($categories as $category) {
            echo '<li class="hkb_category_widget__category_item">';
            if ($disp_article_count) {
                echo '<span class="hkb_category_widget__article_count">' . hkb_get_term_count($category) . '</span>';
            }
            echo '<a href="' . get_term_link($category) . '" title="' . sprintf(__('View all posts in %s', 'ht-knowledge-base'), $category->name) . '" ' . '>' . $category->name . '</a></li> ';
        }
        echo '</ul>';
        ?>
								
								<?php 
        /* After widget (defined by themes). */
        echo $after_widget;
    }
 /**
  * Print the term count
  * @param (Object) $category The category (not required)
  */
 function hkb_term_count($category = null)
 {
     echo hkb_get_term_count($category);
 }