'featured-posts', 'description' => _a('Slides featured posts')); $control_ops = array('width' => 500); $this->WP_Widget('atom-featured-posts', _a('Featured Posts'), $widget_ops, $control_ops); // include in jQuery(document).ready() atom_add('jquery_init', array(&$this, 'js')); atom_add('feature_posts', array(&$this, 'flush_cache')); add_action('save_post', array(&$this, 'flush_cache')); add_action('deleted_post', array(&$this, 'flush_cache')); } function flush_cache(){ wp_cache_delete('widget_featured_posts', 'widget'); } function js(){ // we need to process all instances because this function gets to run only once $widget_settings = atom_get_options($this->option_name); foreach((array)$widget_settings as $instance => $options): // identify instance $id = "{$this->id_base}-{$instance}"; $block_id = "instance-{$id}"; if(is_active_widget(false, $id, $this->id_base)): ?> $("# .featured-posts .cycle").each(function(index, value){ var count = (index + 1) * 150; var list = $(this), featured_cycle = function(){ list.cycle({ fx: '', speed: , pause: true, prev: '# .block-featured a.prev', next: '# .block-featured a.next', easing: '', timeout: }); }; setTimeout(featured_cycle, count); }); $('# .featured-posts li').hover(function(){ $('.caption', this).stop().animate({bottom:'0px',opacity:1},{queue:false,duration:200,easing:'easeOutExpo'}); }, function() { $('.caption', this).stop().animate({bottom:'-70px',opacity:0},{queue:false,duration:300,easing:'easeInExpo'}); }); \n" ." {THUMBNAIL}\n" ."\n"; } // by azspot at gmail dot com -- http://www.php.net/manual/en/function.array-chunk.php#75022 function array_chunk_fixed($list, $parts){ $total_length = count($list); $part_length = floor($total_length / $parts); $part_rem = $total_length % $parts; $output = array(); $mark = 0; for ($i = 0; $i < $parts; $i++): $inc = ($i < $part_rem) ? $part_length + 1 : $part_length; $output[$i] = array_slice($list, $mark, $inc); if(empty($output[$i])) unset($output[$i]); $mark += $inc; endfor; return $output; } function get_featured_posts($args){ global $post; extract($args); // restrict to a specific date range // based on Austin Matzko's code from wp-hackers email list $time = date('Y-m-d', strtotime('-'.intval($timeframe).' days')); $where = create_function('$a', 'return $a.'.'"'." AND post_date > '$time'".'"'.';'); add_filter("posts_where", $where); $posts = new WP_Query(); $query = array('cat' => ($source == 'category') ? intval($category) : false, 'post__in' => ($source == 'marked') ? explode(',', atom_get_options('featured_posts')) : false, 'caller_get_posts' => 1, // exclude sticky posts 'orderby' => $order, 'posts_per_page' => $number, ); $posts->query(apply_filters('atom_featured_posts_query', $query, $args, $this)); $items = array(); $count = 0; while ($posts->have_posts()): $posts->the_post(); $items[$count] = $post; $count++; endwhile; if($max_columns > 0) $items = $this->array_chunk_fixed($items, $max_columns); // restore original query so we don't interfere with other loops wp_reset_query(); remove_filter("posts_where", $where); return empty($posts) ? false : $items; // return the items array if posts were found, otherwise false } function widget($args, $instance){ $cache = wp_cache_get('widget_featured_posts', 'widget'); if (!is_array($cache)) $cache = array(); if (isset($cache[$args['widget_id']])): echo $cache[$args['widget_id']]; return; endif; extract($args, EXTR_SKIP); $instance = wp_parse_args($instance, $this->defaults()); $posts = $this->get_featured_posts($instance); if(!$posts) return atom_add_debug_message("No relevant featured posts found {$args['widget_id']} ({$args['widget_name']}). Widget marked as inactive"); ob_start(); echo $before_widget; ?>
/>
get_field_id('max_columns').'" name="'.$this->get_field_name('max_columns').'" type="text" value="'.(isset($instance['max_columns']) ? intval($instance['max_columns']) : null).'" size="3" />'; ?>
get_field_id('timeframe').'" name="'.$this->get_field_name('timeframe').'" type="text" value="'.(isset($instance['timeframe']) ? intval($instance['timeframe']) : null).'" size="3" />'; ?>
get_field_id('delay').'" name="'.$this->get_field_name('delay').'" type="text" value="'.(isset($instance['delay']) ? intval($instance['delay']) : null).'" size="3" />'; ?>