__( 'Displays most popular posts based on the number of comments', 'themeidol-all-widget' ), ) ); // Refreshing the widget's cached output with each new post add_action( 'save_post', array( $this, 'flush_widget_cache' ) ); add_action( 'deleted_post', array( $this, 'flush_widget_cache' ) ); add_action( 'delete_attachment', array( $this, 'flush_group_cache' ) ); add_action( 'switch_theme', array( $this, 'flush_widget_cache' ) ); } function register_scripts() { wp_register_style('stylish_popular_posts_style', THEMEIDOL_WIDGET_CSS_URL.'stylist-post-style.css'); } public function flush_widget_cache() { wp_cache_delete( 'themeidol-stylistpost', 'widget' ); } /** * Display the widget */ function widget( $args, $instance ) { $cache = (array) wp_cache_get( 'themeidol-stylistpost', 'widget' ); if(!is_array($cache)) $cache = array(); if(isset($cache[$args['widget_id']])){ echo $cache[$args['widget_id']]; return; } ob_start(); extract( $args ); wp_enqueue_style('stylish_popular_posts_style'); /* Variables from the widget settings. */ $title = apply_filters('widget_title', esc_attr($instance['title']) ); $number = esc_attr($instance['number']); $checkbox = esc_attr($instance['checkbox']); $popularity=esc_attr($instance['popularity']); if($popularity=='visited') { $top_popular_posts = new WP_Query( array('ignore_sticky_posts' => 1, 'posts_per_page' => $number, 'post_status' => 'publish', 'orderby' => 'meta_value_num', 'meta_key' => '_themeidol_view_count', 'order' => 'desc', 'paged' => 1)); //$top_popular_posts = new WP_Query('showposts=' . $number . '&meta_key=_themeidol_view_count&orderby=meta_value_num&order=DESC'); } else { echo "not"; $top_popular_posts = new WP_Query( array('ignore_sticky_posts' => 1, 'posts_per_page' => $number, 'post_status' => 'publish', 'orderby' => 'comment_count', 'order' => 'desc', 'paged' => 1)); //$top_popular_posts = new WP_Query('showposts=' . $number . '&orderby=comment_count&order=DESC'); } if ($top_popular_posts->have_posts()) : if (strpos($before_widget, 'widget ') !== false) { $before_widget = preg_replace('/widget /', "idol-widget ", $before_widget, 1); } echo $before_widget; /* Display the widget title. */ if ( $title ) echo $before_title . $title . $after_title; ?>

/>