__('Blogen post widget to display blog posts','blogen'))); } function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', isset($instance['title']) ? $instance['title'] : '', $args['widget_id']); $count = isset($instance['count']) ? $instance['count'] : 5; $order_by = isset($instance['order_by']) ? $instance['order_by'] : 'DESC'; echo wp_kses_post($before_widget); $output = ''; if ( $title ){ echo wp_kses_post($before_title) . esc_html($title) . wp_kses_post($after_title); } global $post; if ( $order_by == 'latest' ) { $args = array( 'posts_per_page' => $count, 'order' => 'DESC' ); } else if ( $order_by == 'popular' ) { $args = array( 'orderby' => 'comment_count', 'posts_per_page' => $count, 'order' => 'DESC' ); } else { $args = array( 'orderby' => 'comment_count', 'order' => 'DESC', 'posts_per_page' => $count ); } $postQuery = get_posts( $args ); if(count($postQuery)>0){ $output .='
'; } echo wp_kses_post($output); echo wp_kses_post($after_widget); } function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags( $new_instance['title'] ); $instance['order_by'] = strip_tags( $new_instance['order_by'] ); $instance['count'] = strip_tags( $new_instance['count'] ); return $instance; } function form($instance) { $defaults = array( 'title' => __('Popular Posts', 'blogen'), 'order_by' => 'latest', 'count' => 2 ); $instance = wp_parse_args( (array) $instance, $defaults ); ?>
__('Popular', 'blogen'), 'latest' => __('Latest', 'blogen'), 'comments' => __('Most Commented', 'blogen'), ); if(isset($instance['order_by'])) $order_by = $instance['order_by']; ?>