'widget-blogsquare-recent widget-posts-thumbnail', 'description' => __( 'Display recent posts with thumbnails.', 'blogsquare' ) ); // Create the widget. parent::__construct( 'blogsquare-recent', // $this->id_base __( '» Recent Posts', 'blogsquare' ), // $this->name $widget_options // $this->widget_options ); // Flush the transient. add_action( 'save_post' , array( $this, 'flush_widget_transient' ) ); add_action( 'deleted_post', array( $this, 'flush_widget_transient' ) ); add_action( 'switch_theme', array( $this, 'flush_widget_transient' ) ); } /** * Outputs the widget based on the arguments input through the widget controls. * * @since 1.0.0 */ function widget( $args, $instance ) { // Default value. $defaults = array( 'title' => '', 'limit' => 6, 'show_number' => true ); $instance = wp_parse_args( (array) $instance, $defaults ); extract( $args ); // Output the theme's $before_widget wrapper. echo wp_kses_post( $before_widget ); // If the title not empty, display it. if ( $instance['title'] ) { echo wp_kses_post( $before_title ) . wp_kses_post( apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) ) . wp_kses_post( $after_title ); } // Display the recent posts. if ( false === ( $recent = get_transient( 'blogsquare_recent_widget_' . $this->id ) ) ) { // Posts query arguments. $args = array( 'post_type' => 'post', 'posts_per_page' => $instance['limit'], ); // The post query $recent = new WP_Query( $args ); // Store the transient. set_transient( 'blogsquare_recent_widget_' . $this->id, $recent ); } global $post; $i = 1; if ( $recent->have_posts() ) { echo '
id="get_field_id( 'show_number' ) ); ?>" name="get_field_name( 'show_number' ) ); ?>" />