'recent_posts_a clearfix', 'description' => __( 'Recent posts widget Type A (front page)', 'awie') ); parent::__construct('recent_posts_a', __('Flymag: Recent posts type A', 'awie'), $widget_ops); $this->alt_option_name = 'recent_posts_a'; add_action( 'save_post', array($this, 'flush_widget_cache') ); add_action( 'deleted_post', array($this, 'flush_widget_cache') ); add_action( 'switch_theme', array($this, 'flush_widget_cache') ); } public function widget($args, $instance) { $cache = array(); if ( ! $this->is_preview() ) { $cache = wp_cache_get( 'recent_posts_a', 'widget' ); } if ( ! is_array( $cache ) ) { $cache = array(); } if ( ! isset( $args['widget_id'] ) ) { $args['widget_id'] = $this->id; } if ( isset( $cache[ $args['widget_id'] ] ) ) { echo $cache[ $args['widget_id'] ]; return; } ob_start(); $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : ''; $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); $category = isset( $instance['category'] ) ? esc_attr($instance['category']) : ''; $bg_color = isset( $instance['bg_color'] ) ? esc_attr($instance['bg_color']) : ''; $text_color = isset( $instance['text_color'] ) ? esc_attr($instance['text_color']) : ''; $r = new WP_Query( apply_filters( 'widget_posts_args', array( 'posts_per_page' => 4, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true, 'category_name' => $category, ) ) ); if ($r->have_posts()) : ?>
is_preview() ) { $cache[ $args['widget_id'] ] = ob_get_flush(); wp_cache_set( 'recent_posts_a', $cache, 'widget' ); } else { ob_end_flush(); } } public function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); $instance['category'] = strip_tags($new_instance['category']); $instance['bg_color'] = strip_tags($new_instance['bg_color']); $instance['text_color'] = strip_tags($new_instance['text_color']); $this->flush_widget_cache(); $alloptions = wp_cache_get( 'alloptions', 'options' ); if ( isset($alloptions['recent_posts_a']) ) delete_option('recent_posts_a'); return $instance; } public function flush_widget_cache() { wp_cache_delete('recent_posts_a', 'widget'); } public function form( $instance ) { $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; $category = isset( $instance['category'] ) ? esc_attr( $instance['category'] ) : ''; $bg_color = isset( $instance['bg_color'] ) ? esc_attr( $instance['bg_color'] ) : ''; $text_color = isset( $instance['text_color'] ) ? esc_attr( $instance['text_color'] ) : ''; ?>