'themeidol-recent', 'description' => __('Displays the most recent posts with date and thumbnail.', 'themeidol-all-widget')); parent::__construct('themeidol-recent-posts', __('Themeidol - Recent Posts', 'themeidol-all-widget'), $args); $this->alt_option_name = 'themeidol-recent-posts'; 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')); } function widget($args, $instance){ $cache = wp_cache_get('themeidol-recent-posts', 'widget'); if(!is_array($cache)) $cache = array(); if(isset($cache[$args['widget_id']])){ echo $cache[$args['widget_id']]; return; } ob_start(); extract($args); $title = apply_filters('widget_title', esc_attr($instance['title'])); $type = esc_attr($instance['type']); if($type == '') $type = 'post'; $number = esc_attr($instance['number']); if(!is_numeric($number)) $number = 5; elseif($number < 1) $number = 1; elseif($number > 99) $number = 99; $recent_posts = new WP_Query(array('post_type' => $type, 'posts_per_page' => $number, 'ignore_sticky_posts' => 1)); if($recent_posts->have_posts()): echo $before_widget; if($title != '') echo $before_title.$title.$after_title; ?>