__('Shows most recent posts. You can customize it easily.', 'adv-recent-posts') ); //Create widget $this->WP_Widget('advancedrecentposts', __('Advanced Recent Posts', 'adv-recent-posts'), $widget_ops); } function widget($args, $instance) { extract($args, EXTR_SKIP); echo $before_widget; $title = empty($instance['title']) ? __('Recent Posts', 'adv-recent-posts') : apply_filters('widget_title', $instance['title']); $link = empty($instance['link']) ? '' : $instance['link']; $parameters = array( 'title' => $title, 'link' => $instance['link'], 'separator' => $instance['separator'], 'show_type' => $instance['show_type'], 'limit' => (int) $instance['show-num'], 'excerpt' => (int) $instance['excerpt-length'], 'actcat' => (bool) $instance['actcat'], 'cats' => esc_attr($instance['cats']), 'cusfield' => esc_attr($instance['cus-field']), 'w' => (int) $instance['width'], 'h' => (int) $instance['height'], 'firstimage' => (bool) $instance['firstimage'], 'atimage' =>(bool) $instance['atimage'], 'defimage' => esc_url($instance['defimage']), 'showauthor' => (bool) $instance['showauthor'], 'showtime' => (bool) $instance['showtime'], 'format' => esc_attr($instance['format']), 'spot' => esc_attr($instance['spot1']) ? esc_attr($instance['spot1']) : (esc_attr($instance['spot2']) ? esc_attr($instance['spot2']) : esc_attr($instance['spot1'])), ); if ( !empty( $title ) && !empty( $link ) ) { echo $before_title . '' . $title . '' . $after_title; } else if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } //print recent posts echo yg_recentposts($parameters); echo $after_widget; } //end of widget() //Update widget options function update($new_instance, $old_instance) { $instance = $old_instance; //get old variables $instance['title'] = esc_attr($new_instance['title']); $instance['link'] = esc_attr($new_instance['link']); $instance['separator'] = $new_instance['separator']; $instance['show_type'] = $new_instance['show_type']; $instance['show-num'] = (int) abs($new_instance['show-num']); if ($instance['show-num'] > 20) $instance['show-num'] = 20; $instance['excerpt-length'] = (int) abs($new_instance['excerpt-length']); $instance['cats'] = esc_attr($new_instance['cats']); $instance['actcat'] = $new_instance['actcat'] ? 1 : 0; $instance['cus-field'] = esc_attr($new_instance['cus-field']); $instance['width'] = esc_attr($new_instance['width']); $instance['height'] = esc_attr($new_instance['height']); $instance['firstimage'] = $new_instance['first-image'] ? 1 : 0; $instance['atimage'] = $new_instance['atimage'] ? 1 : 0; $instance['defimage'] = esc_url($new_instance['def-image']); $instance['showauthor'] = $new_instance['showauthor'] ? 1 : 0; $instance['showtime'] = $new_instance['showtime'] ? 1 : 0; $instance['format'] = esc_attr($new_instance['format']); $instance['spot1'] = esc_attr($new_instance['spot1']); $instance['spot2'] = esc_attr($new_instance['spot2']); $instance['spot3'] = esc_attr($new_instance['spot3']); $instance['spot'] = $instance['spot1'] ? $instance['spot1'] : ($instance['spot2'] ? $instance['spot2'] : $instance['spot3']); return $instance; } //end of update() //Widget options form function form($instance) { $instance = wp_parse_args( (array) $instance, array( 'title' => __('Recent Posts','adv-recent-posts'),'link' => __(get_bloginfo('home').'/blog/','adv-recent-posts'), 'separator' => __(': ','adv-recent-posts'), 'show_type' => 'post', 'show-num' => 10, 'excerpt-length' => 0, 'actcat' => 0, 'cats' => '', 'cus-field' => '', 'width' => '', 'height' => '', 'firstimage' => 0, 'show-time' => 0, 'atimage' => 0,'defimage'=>'','format'=>'m/d/Y', 'spot1'=>'spot1', 'spot2'=>'', 'spot3'=>'' ) ); $title = esc_attr($instance['title']); $link = esc_attr($instance['link']); $separator = $instance['separator']; $show_type = $instance['show_type']; $show_num = (int) $instance['show-num']; $excerpt_length = (int) $instance['excerpt-length']; $cats = esc_attr($instance['cats']); $actcat = (bool) $instance['actcat']; $cus_field = esc_attr($instance['cus-field']); $width = esc_attr($instance['width']); $height = esc_attr($instance['height']); $firstimage = (bool) $instance['firstimage']; $atimage = (bool) $instance['atimage']; $defimage = esc_url($instance['defimage']); $showauthor = (bool) $instance['showauthor']; $showtime = (bool) $instance['showtime']; $format = esc_attr($instance['format']); $spot1 = esc_attr($instance['spot1']); $spot2 = esc_attr($instance['spot2']); $spot3 = esc_attr($instance['spot3']); $spot = $spot1 ? $spot1 : ($spot2 ? $spot2 : $spot3); ?>
px
px
/>
/>
/>
/>
/>
/>
/>
/>
': ','show_type' => 'post', 'limit' => 10, 'excerpt' => 0, 'actcat' => 0, 'cats'=>'', 'cusfield' =>'', 'w' => 48, 'h' => 48, 'firstimage' => 0, 'showauthor' => 0, 'showtime' => 0, 'atimage' => 0, 'defimage' => '', 'format' => 'm/d/Y', 'spot' => 'spot1'); $args = shortcode_atts($defaults, $atts); return yg_recentposts( $args, false ); } function yg_recentposts($args = '', $echo = true) { global $wpdb; $defaults = array('separator' => ': ','show_type' => 'post', 'limit' => 10, 'excerpt' => 0, 'actcat' => 0, 'cats'=>'', 'cusfield' =>'', 'w' => 48, 'h' => 48, 'firstimage' => 0, 'showauthor' => 0, 'showtime' => 0, 'atimage' => 0, 'defimage' => '', 'format' => 'm/d/Y', 'spot' => 'spot1'); $args = wp_parse_args( $args, $defaults ); extract($args); $separator = $separator; $show_type = $show_type; $limit = (int) abs($limit); $firstimage = (bool) $firstimage; $showauthor = (bool) $showauthor; $showtime = (bool) $showtime; $spot = esc_attr($spot); $atimage = (bool) $atimage; $defimage = esc_url($defimage); $format = esc_attr($format); $w = (int) $w; $h = (int) $h; $excerptlength = (int) abs($excerpt); $excerpt = ''; $cats = str_replace(" ", "", esc_attr($cats)); if (($limit < 1 ) || ($limit > 20)) $limit = 10; /*$postlist = wp_cache_get('yg_recent_posts'); //Not yet if ( false === $postlist ) { */ if (($actcat) && (is_category())) { $cats = get_query_var('cat'); } if (($actcat) && (is_single())) { $cats = ''; foreach (get_the_category() as $catt) { $cats .= $catt->cat_ID.' '; } $cats = str_replace(" ", ",", trim($cats)); } if (!intval($cats)) $cats=''; $query = "cat=$cats&showposts=$limit&post_type=$show_type"; $posts = get_posts($query); //get posts $postlist = ''; $height = $h ? ' height = "' . $h .'"' : ''; $width = $w ? ' width = "' . $w . '"' : ''; foreach ($posts as $post) { if ($showtime) { $time = ' '. date($format,strtotime($post->post_date)); } $post_title = stripslashes($post->post_title); if ($excerptlength) { $excerpt = $post->post_excerpt; if ( '' == $excerpt ) { $text = $post->post_content; $text = strip_shortcodes( $text ); $text = str_replace(']]>', ']]>', $text); $text = strip_tags($text); $excerpt_length = 100; $words = explode(' ', $text, $excerpt_length + 1); if (count($words) > $excerpt_length) { array_pop($words); $text = implode(' ', $words); } $excerpt = $text; } if(strlen($excerpt) > $excerptlength) { $excerpt = mb_substr($excerpt, 0, $excerptlength) . '...'; } $excerpt = $separator . ($spot == 'spot3' ? ''.$time.' ' : '') . $excerpt; } $image = ''; $img = ''; if ($cusfield) { $cusfield = esc_attr($cusfield); $img = get_post_meta($post->ID, $cusfield, true); } if (!$img && $firstimage) { $match_count = preg_match_all("/