class Shaka_Categories_Widget extends WP_Widget{
function __construct() {
parent::__construct(
\'shaka_categories_widget\', // Base ID
\'Shaka Categories\', // Name
array(\'description\' => __( \'Displays post Categories with counts\'))
);
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance[\'title\'] = strip_tags($new_instance[\'title\']);
//$instance[\'post_type\'] = strip_tags($new_instance[\'post_type\']);
//$instance[\'numberOfListings\'] = strip_tags($new_instance[\'numberOfListings\']);
return $instance;
}
function form($instance) {
if( $instance) {
$title = esc_attr($instance[\'title\']);
} else {
$title = \'\';
}
?>
<p>
<label for="<?php echo $this->get_field_id(\'title\'); ?>"><?php _e(\'Title\', \'sim_most_viewed\'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id(\'title\'); ?>" name="<?php echo $this->get_field_name(\'title\'); ?>" type="text" value="<?php echo $title; ?>" />
</p>
<?php
}
function widget($args, $instance) {
extract( $args );
$title = apply_filters(\'widget_title\', $instance[\'title\']);
echo $before_widget;
if ( $title ) {
echo $before_title . $title . $after_title;
}
$this->getMostViewedListings();
echo $after_widget;
}
function getMostViewedListings() { //html
$args = array(
\'type\' => \'post\'
);
$categories = get_categories($args);
//echo "<pre>";var_dump($categories);echo "</pre>";
if($categories){
echo "<ul>";
foreach($categories as $cat){
echo "<li><a href=\'".site_url().\'/category/\'.$cat->slug."\' class=\'cat-item cat-item-".$cat->term_id."\'>".$cat->name." <span class=\'post-count\'>".$cat->count."</span></a></li>";
}
echo "</ul>";
}
}
} //end class
register_widget(\'Shaka_Categories_Widget\');