function widget($args, $instance) { global $comments, $comment; $cache = wp_cache_get('widget_recent_comments', '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; } extract($args, EXTR_SKIP); $output = ''; $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments', 'be-themes') : $instance['title'], $instance, $this->id_base); if (empty($instance['number']) || !($number = absint($instance['number']))) { $number = 3; } $comments = get_comments(array('number' => $number, 'status' => 'approve', 'post_status' => 'publish')); $output .= $before_widget; if ($title) { $output .= $before_title . $title . $after_title; } $output .= '<ul id="recentcomments">'; if ($comments) { foreach ((array) $comments as $comment) { $output .= '<li class="recent_comments sec-border-bottom"><div class="left"><i class="font-icon icon-comment"></i></div><div class="recent-comment-text">' . sprintf(__('%2$s', 'be-themes'), get_comment_author_link(), '<a href="' . esc_url(get_comment_link($comment->comment_ID)) . '">' . be_themes_trim_content($comment->comment_content, 60) . '</a>') . '<br /><span class="secondary_text alt-color"><i class="icon-clock"></i>' . get_comment_date("F j, Y", $comment->comment_ID) . '</span></div></li>'; } } $output .= '</ul>'; $output .= $after_widget; echo $output; $cache[$args['widget_id']] = $output; wp_cache_set('widget_recent_comments', $cache, 'widget'); }
function widget($args, $instance) { $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 = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts', 'be_themes') : $instance['title'], $instance, $this->id_base); if (empty($instance['number']) || !($number = absint($instance['number']))) { $number = 10; } $r = new WP_Query(array('posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true)); if ($r->have_posts()) { ?> <?php echo $before_widget; ?> <?php if ($title) { echo $before_title . $title . $after_title; } ?> <ul class="recent_post_container"> <?php while ($r->have_posts()) { $r->the_post(); ?> <li class="recent_posts clearfix sec-border-bottom"> <?php if (has_post_thumbnail(get_the_ID())) { ?> <div class="recent_post_img"> <a href="<?php the_permalink(); ?> " title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?> "> <?php echo get_the_post_thumbnail(get_the_ID(), "blog-widget", array('class' => 'sec-bg sec-border be-shadow')); ?> </a> </div> <?php } ?> <div class="recent_post_content"> <a href="<?php the_permalink(); ?> " title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?> "> <?php echo be_themes_trim_content(get_the_title(), 100); ?> </a> <span class="secondary_text alt-color"><i class="icon-clock"></i><?php echo get_the_date("F j, Y"); ?> </span> </div> </li> <?php } ?> </ul> <?php echo $after_widget; ?> <?php // Reset the global $the_post as this query will have stomped on it wp_reset_postdata(); } $cache[$args['widget_id']] = ob_get_flush(); wp_cache_set('widget_recent_posts', $cache, 'widget'); }