__( 'A widget To Display Recent Posts', 'bloger' ) ) ); } /** * Helper function that holds widget fields * Array is used in update and form functions */ private function widget_fields() { $fields = array( 'recent_post_title' => array( 'bloger_widgets_name' => 'recent_post_title', 'bloger_widgets_title' => __('Title','bloger'), 'bloger_widgets_field_type' => 'text', ), 'recent_post_show_num' => array( 'bloger_widgets_name' => 'recent_post_show_num', 'bloger_widgets_title' => __('No of posts to show','bloger'), 'bloger_widgets_field_type' => 'number', 'bloger_widgets_description' => __('Displays the latest five post if left empty','bloger'), ), 'recent_post_show_img' => array( 'bloger_widgets_name' => 'recent_post_show_img', 'bloger_widgets_title' => __('Display post image?','bloger'), 'bloger_widgets_field_type' => 'checkbox', ), ); return $fields; } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget( $args, $instance ) { extract($args); if($instance!=null){ $post_num = empty($instance['recent_post_show_num']) ? '5' : $instance['recent_post_show_num']; $recent_args = array( 'post_type' =>'post', 'posts_per_page' => $post_num, 'order' => 'DESC', 'status' => 'publish', ); $recent_post_query = new WP_Query($recent_args); $recent_post_title = empty($instance['recent_post_title']) ? false : $instance['recent_post_title']; $show_img = empty($instance['recent_post_show_img']) ? false : $instance['recent_post_show_img']; echo $before_widget; ?>