'widget_popular_entries', 'description' => __( "The most Popular posts on your site", 'affiliate-booster' ) ); parent::__construct('Popular-posts', __('Popular Posts', 'affiliate-booster'), $widget_ops); $this->alt_option_name = 'widget_popular_entries'; add_action( 'save_post', array($this, 'flush_widget_cache') ); add_action( 'deleted_post', array($this, 'flush_widget_cache') ); add_action( 'switch_theme', array($this, 'flush_widget_cache') ); } function widget($args, $instance) { $cache = wp_cache_get('widget_popular_posts', 'widget'); if ( !is_array($cache) ) $cache = array(); if ( ! isset( $args['widget_id'] ) ) $args['widget_id'] = $this->id; if ( isset( $cache[ $args['widget_id'] ] ) ) { echo $cache[ $args['widget_id'] ]; return; } ob_start(); extract($args); $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Popular Posts', 'affiliate-booster' ); $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 10; $orderby = ( ! empty( $instance['order_by'] ) ) ? $instance['order_by'] : 'ASC'; if ( ! $number ) $number = 10; $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false; $order_by = $instance['order_by']; if( $order_by == 'comment_count'){ $args = array('orderby' => 'comment_count', 'posts_per_page'=> $number); } else{ $args = array( 'posts_per_page' => $number, 'meta_key' => $order_by, 'orderby' => 'meta_value_num', ); } $r = new WP_Query( $args ); if ($r->have_posts()) :?>
id="get_field_id( 'show_date' ); ?>" name="get_field_name( 'show_date' ); ?>" />
id; } $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Posts', 'affiliate-booster' ); /** 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['number'] ) ) ? absint( $instance['number'] ) : 5; if ( ! $number ) $number = 5; $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false; /** * Filter the arguments for the Recent Posts widget. * * @since 3.4.0 * * @see WP_Query::get_posts() * * @param array $args An array of arguments used to retrieve the recent posts. */ $r = new WP_Query( apply_filters( 'widget_posts_args', array( 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) ) ); if ($r->have_posts()) : ?> '.$args['before_title'] . $title . $args['after_title'].''; } ?>