'recent_posts_c recent_posts_f clearfix', 'description' => __( 'Recent posts widget Type F - one category', 'awie') ); parent::__construct('recent_posts_f', __('Awye: Recent posts type F', 'awie'), $widget_ops); $this->alt_option_name = 'recent_posts_f'; 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_f', '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(); $cat_one = isset( $instance['cat_one'] ) ? esc_attr($instance['cat_one']) : ''; $bg_color = isset( $instance['bg_color'] ) ? esc_attr($instance['bg_color']) : ''; $text_color = isset( $instance['text_color'] ) ? esc_attr($instance['text_color']) : ''; $first_query = new WP_Query( array( 'posts_per_page' => 1, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true, 'category_name' => $cat_one, ) ); $secound_query = new WP_Query( array( 'posts_per_page' => 4, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true, 'category_name' => $cat_one, 'offset' => 1, ) ); ?>
' . $cat -> name . ''; } ?> have_posts() ) : $first_query->the_post(); ?>
have_posts() ) : $secound_query->the_post(); ?>
is_preview() ) { $cache[ $args['widget_id'] ] = ob_get_flush(); wp_cache_set( 'recent_posts_f', $cache, 'widget' ); } else { ob_end_flush(); } } public function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['cat_one'] = strip_tags($new_instance['cat_one']); $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_f']) ) delete_option('recent_posts_f'); return $instance; } public function flush_widget_cache() { wp_cache_delete('recent_posts_f', 'widget'); } public function form( $instance ) { $cat_one = isset( $instance['cat_one'] ) ? esc_attr( $instance['cat_one'] ) : ''; $bg_color = isset( $instance['bg_color'] ) ? esc_attr( $instance['bg_color'] ) : ''; $text_color = isset( $instance['text_color'] ) ? esc_attr( $instance['text_color'] ) : ''; ?>