', $this->get_field_id( 'title' ), esc_html__( 'Title', 'ac-repair' ), $this->get_field_name( 'title' ), esc_attr( $title ) ); $limit = isset ( $instance['limit'] ) ? $instance['limit'] : absint('3'); $limit = esc_attr( $limit ); printf( '


', $this->get_field_id( 'limit' ), esc_html__( 'Limit', 'ac-repair' ), $this->get_field_name( 'limit' ), absint( $limit ) ); } /** * Renders the output. * * @see WP_Widget::widget() */ public function widget( $args, $instance ){ // Widget output extract($args); $title = isset($instance['title']) ? $instance['title'] : esc_html__('Recent Post', 'ac-repair'); $limit = isset($instance['limit']) ? $instance['limit'] : absint('3'); print $before_widget . $before_title . esc_html($title) . $after_title ; $sidebar_var = array( 'post_type' => 'post', 'post_status'=> 'publish', 'posts_per_page' => absint($limit), ); $blog_post_query = new WP_Query($sidebar_var); if($blog_post_query->have_posts()) : while($blog_post_query->have_posts()) : $blog_post_query->the_post(); if ( has_post_thumbnail() ) : $comments = ( get_comments_number() == 1 ? (get_comments_number()) : (get_comments_number()) ); $post_data = ''; $post_data .= '
'; $post_data .= '
'. get_the_time('d') . '
'. get_the_time('F'). '
'; $post_data .= '
'. $comments .'
'; print '
'; ?>

"; endif; endwhile; endif; wp_reset_postdata(); print $after_widget; } /** * Prepares the content. Not. * * @param array $new_instance New content * @param array $old_instance Old content * @return array New content */ public function update( $new_instance, $old_instance ){ $new_instance_array = array( 'title', 'limit' ); foreach( $new_instance_array as $val ) $old_instance[ $val ] = $new_instance[ $val ]; return $old_instance; } /** * Tell WP we want to use this widget. * * @wp-hook widgets_init * @return void */ public static function register(){ register_widget( __CLASS__ ); } }