* @copyright Copyright (c) 2018, Radiuzz * @link http://caelum.radiuzz.com * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 or later */ /** * Core class used to implement a About Author widget. * * @see WP_Widget */ class caelum_Widget_Popular_Posts extends WP_Widget { public function __construct() { parent::__construct( 'popular-posts-widget', // Widget ID esc_html__( 'caelum: Popular Posts', 'caelum' ), // Widget Name. array( 'classname' => 'popular-posts-widget', // Widget Class. 'description' => esc_html__( 'A widget that displays popular posts.', 'caelum' ), // Widget Description. ) ); } /** * Outputs the content for the current About me widget instance. * * @param array $args Display arguments including 'before_title', 'after_title', * 'before_widget', and 'after_widget'. * @param array $instance Settings for the current Archives widget instance. */ function widget( $args, $instance ) { extract( $args ); /* Our variables from the widget settings. */ $title = null; if (isset( $instance['title'] )) { $title = apply_filters('widget_title', $instance['title'] ); } $categories = null; if (isset($instance['categories'])) { $categories = $instance['categories']; } $number = null; if (isset($instance['number'])) { $number = $instance['number']; } $query = array( 'showposts' => $number, 'nopaging' => 0, 'orderby' => 'meta_value_num', 'meta_key' => 'post_views_count', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'cat' => $categories ); $loop = new WP_Query($query); if ($loop->have_posts()) : /* Before widget */ echo $before_widget; /* Display the widget title if one was input. */ if ( $title ) echo $before_title . $title . $after_title; ?> 'Popular Posts', 'number' => 5, 'categories' => ''); $instance = wp_parse_args( (array) $instance, $defaults ); ?>