'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'; // Register site styles and scripts add_action( 'wp_enqueue_scripts', array( $this, 'register_widget_styles' ) ); 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()): $before_widget = str_replace('widget ', 'idol-widget ', $before_widget); echo $before_widget; if($title != '') echo $before_title.$title.$after_title; ?>
have_posts()): $recent_posts->the_post(); ?>
'')); ?>
flush_widget_cache(); $alloptions = wp_cache_get('alloptions', 'options'); if(isset($alloptions['themeidol-recent-posts'])) delete_option('themeidol-recent-posts'); return $instance; } function flush_widget_cache(){ wp_cache_delete('cpotheme-recent-posts', 'widget'); } /** * Registers and enqueues widget-specific styles. */ public function register_widget_styles() { wp_enqueue_style( 'themeidol-recentpost', THEMEIDOL_WIDGET_CSS_URL.'recentpost-style.css'); } // end register_widget_styles function form($instance){ $instance = wp_parse_args((array) $instance, array('title' => '')); $title = esc_attr($instance['title']); $type = isset($instance['type']) ? esc_attr($instance['type']) : 'post'; if(!isset($instance['number']) || !$number = intval($instance['number'])) $number = 5; ?>