function widget($args, $instance) { $cache = array(); if (!$this->is_preview()) { $cache = wp_cache_get('widget_recent_posts', '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(); extract($args); $title = !empty($instance['title']) ? $instance['title'] : 'Recent Posts'; /** This filter is documented in wp-includes/default-widgets.php */ $title = apply_filters('widget_title', $title, $instance, $this->id_base); $number = !empty($instance['number']) ? absint($instance['number']) : 5; if (!$number) { $number = 5; } $show_date = isset($instance['show_date']) ? $instance['show_date'] : false; /** * Filter the arguments for the Recent Posts widget. * * @since 3.4.0 * * @see WP_Query::get_posts() * * @param array $args An array of arguments used to retrieve the recent posts. */ $r = new WP_Query(apply_filters('widget_posts_args', array('posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true))); global $post; if ($r->have_posts()) { if ($title) { echo $before_title . $title . $after_title; } ?> <?php while ($r->have_posts()) { $r->the_post(); ?> <div class="item"> <?php $featuredImage = wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?> <div class="img-container"> <a href="<?php the_permalink(); ?> " class="single-image link-icon"> <img src="<?php echo $featuredImage; ?> " alt="Photo" /> </a> </div> <h6 class="title"><a href="<?php the_permalink(); ?> "><?php get_the_title() ? the_title() : the_ID(); ?> </a></h6> <div class="entry-body"><?php bguru_excerpt('bguru_excerptlength_index', ''); ?> </div> <a class="button default color" href="<?php the_permalink(); ?> ">Read More</a> </div> <?php } ?> <?php // Reset the global $the_post as this query will have stomped on it wp_reset_postdata(); } if (!$this->is_preview()) { $cache[$args['widget_id']] = ob_get_flush(); wp_cache_set('widget_recent_posts', $cache, 'widget'); } else { ob_end_flush(); } }
<span class="tag"><?php the_tags(); ?> </span> <span class="comments"><a href="#"><?php echo get_comments_number(); ?> Comments</a></span> </div> <div class="entry-body"> <?php bguru_excerpt('bguru_excerptlength_index', ''); ?> <a class="button default color" href="<?php the_permalink(); ?> ">Read More</a> </div><!--/ .entry-body--> </article> <?php } ?> <?php