@Sandun why don’t you create your own widget?
<?php
class Category_List_Custom extends WP_Widget {
/**
* Sets up the widgets name etc
*/
public function __construct() {
$widget_ops = array(
'classname' => 'category_list_custom',
'description' => 'Category list custom',
);
parent::__construct( 'category_list_custom', 'Category List Custom', $widget_ops );
}
/**
* Outputs the content of the widget
*
* @param array $args
* @param array $instance
*/
public function widget( $args, $instance ) {
$cats = get_categories();
$ordered_cats = array();
foreach($cats as $cat){
$ordered_cats[$cat->category_count] = $cat;
}
ksort($ordered_cats);
$return = '<ul>';
foreach($ordered_cats as $cat){
$return .= '<li>' . $cat->name . '</li>';
}
$return .= '</ul>';
return $return;
}
}
add_action( 'widgets_init', function(){
register_widget( 'Category_List_Custom' );
});?>
It should be something very similar to this.
Let me know if it helps.