'widget-vt-blogging-popular widget_posts_thumbnail', 'description' => esc_html__('A widget that displays popular posts by comments with thumbnails.', 'vt-blogging') ); // Create the widget. parent::__construct( 'vt-blogging-popular', // $this->id_base __( '[VT] Popular Posts', 'vt-blogging' ), // $this->name $widget_ops // $this->widget_options ); // Flush the transient. add_action( 'save_post' , array( $this, 'flush_widget_transient' ) ); add_action( 'deleted_post', array( $this, 'flush_widget_transient' ) ); add_action( 'switch_theme', array( $this, 'flush_widget_transient' ) ); } /** * Outputs the widget based on the arguments input through the widget controls. * * @since 1.0.0 */ function widget( $args, $instance ) { extract( $args ); // Output the theme's $before_widget wrapper. echo $before_widget; // If the title not empty, display it. if ( $instance['title'] ) { echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title; } // Display the popular posts. if ( false === ( $popular = get_transient( 'vt_blogging_popular_widget_' . $this->id ) ) ) { // Posts query arguments. $args = array( 'post_type' => 'post', 'posts_per_page' => $instance['limit'], 'orderby' => 'comment_count' ); // The post query $popular = new WP_Query( $args ); // Store the transient. set_transient( 'vt_blogging_popular_widget_' . $this->id, $popular ); } global $post; if ( $popular->have_posts() ) { echo '
id="get_field_id( 'show_views' ); ?>" name="get_field_name( 'show_views' ); ?>" />