__('Bug Blog recent posts widget to display recent posts', 'bug-blog'))); } /*------------------------------------------------------- * Front-end display of widget *-------------------------------------------------------*/ function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base ); $count = $instance['count']; $order_by = $instance['order_by']; $text_color = $instance['text_color']; 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' => 'meta_value_num', 'meta_key' => 'post_views_count', 'posts_per_page' => $count, 'order' => 'DESC' ); } else { $args = array( 'orderby' => 'comment_count', 'order' => 'DESC', 'posts_per_page' => $count ); } $posts = get_posts( $args ); if(count($posts)>0){ $output .='
'; foreach ($posts as $post): setup_postdata($post); $output .='
'; if(has_post_thumbnail()): $output .=''; endif; $output .='
'; $output .= '

'. esc_html( get_the_title() ) .'

'; $output .= ''; $output .='
'; $output .='
'; endforeach; wp_reset_postdata(); $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'] ); $instance['text_color'] = strip_tags( $new_instance['text_color'] ); return $instance; } function form($instance) { $defaults = array( 'title' => __('Latest Posts', 'bug-blog'), 'order_by' => 'latest', 'count' => 5 ); $instance = wp_parse_args( (array) $instance, $defaults ); ?>

__('Popular', 'bug-blog'), 'latest' => __('Latest', 'bug-blog'), 'comments' => __('Most Commented', 'bug-blog') ); if(isset($instance['order_by'])) $order_by = $instance['order_by']; ?>