This WordPress plugin "Category Popular Posts" is to show category wise top popular posts in a widget. The widget has options to add a description, limit the number of posts, an option to show date or not, an option to show the author or not, and an option to show the featured image or not.
Installation:
- Download from the above link and got to WordPress admin >> Plugins >> Add Plugin and upload the downloaded zip file "category-popular-posts.zip".
- Then go to Appearance >> Widgets >> Add the "Category wise Popular posts" widgets to the widgets places like in the sidebar.
Settings:
Enter title, if needed description, number of posts to show here in our example it is 6, choose an option Yes or no to show date, author and featured image, click save and done.

Frontend view:
It displays popular posts of the category in the categories pages, and on the posts page, it displays the popular posts of the active post's category posts.

CSS change:
You can make the CSS changes for the following CSS classes to match your theme design:
- .post-image: for the image
- .post-content: for the content
- For others just target as per your need.
The code is written as below:
'Description', 'id' => 'description_textarea', 'type' => 'textarea', ), array( 'label' => 'Limit', 'id' => 'limit_number', 'type' => 'number', ), array( 'label' => 'Show date', 'id' => 'showdate_select', 'type' => 'select', 'options' => array( 'Yes', 'No', ), ), array( 'label' => 'Show Author', 'id' => 'showauthor_select', 'type' => 'select', 'options' => array( 'Yes', 'No', ), ), array( 'label' => 'Show featured image', 'id' => 'showfeaturedima_select', 'type' => 'select', 'options' => array( 'Yes', 'No', ), ), ); public function widget($args, $instance) { if (!isset($args['widget_id'])) { $args['widget_id'] = $this->id; } $title = (!empty($instance['title'])) ? $instance['title'] : __('Recent Posts'); /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ $title = apply_filters('widget_title', $title, $instance, $this->id_base); $number = (!empty($instance['limit_number'])) ? absint($instance['limit_number']) : 5; if (!$number) { $number = 5; } $show_date = isset($instance['showdate_select']) ? $instance['showdate_select'] : false; $r = new WP_Query( apply_filters( 'widget_posts_args', array( 'meta_key' => 'post_views_count', 'cat' => get_query_var('cat'), 'orderby' => 'meta_value_num', 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true, ), $instance ) ); if (!$r->have_posts()) { return; } echo $args['before_widget']; if ($title) { echo $args['before_title'] . $title . $args['after_title']; } echo '' . $instance['description_textarea'] . '
'; echo ""; echo '
- ';
foreach ($r->posts as $recent_post):
$post_title = get_the_title($recent_post->ID);
$p_title = (!empty($post_title)) ? $post_title : __('(no title)');
echo "
- ";
if ($instance['showfeaturedima_select'] == "Yes") {
echo "";
}
echo "" . $recent_post->post_title . ""; if ($instance['showauthor_select'] == "Yes") { echo ""; echo ""; echo "
- " . get_the_author_meta('display_name', $recent_post->post_author) . ""; } if ($instance['showdate_select'] == "Yes") { echo "
" . get_the_date('', $recent_post->ID) . ""; } echo " ";
endforeach;
echo "
'; $output .= ' '; $output .= ''; $output .= '
'; break; case 'select': $output .= ''; $output .= ' '; $output .= ''; $output .= '
'; break; default: $output .= ''; $output .= ' '; $output .= ''; $output .= '
'; } } echo $output; } public function form($instance) { $title = !empty($instance['title']) ? $instance['title'] : esc_html__('', 'textdomain'); ?>field_generator($instance); } public function update($new_instance, $old_instance) { $instance = array(); $instance['title'] = (!empty($new_instance['title'])) ? strip_tags($new_instance['title']) : ''; foreach ($this->widget_fields as $widget_field) { switch ($widget_field['type']) { default: $instance[$widget_field['id']] = (!empty($new_instance[$widget_field['id']])) ? strip_tags($new_instance[$widget_field['id']]) : ''; } } return $instance; } } function register_categorywisepopularp_widget() { register_widget('Categorywisepopularp_Widget'); } add_action('widgets_init', 'register_categorywisepopularp_widget');
Please let us know if you have any suggestions or requirements, you can also find us on Twitter and Facebook. Enjoy!