/** * Outputs the HTML for this widget. * * @param array $args An array of standard parameters for widgets in this theme * @param array $instance An array of settings for this widget instance * * @return void Echoes it's output */ public function widget($args, $instance) { global $comments, $comment; $cache = array(); if (!$this->is_preview()) { $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; } $output = ''; $title = !empty($instance['title']) ? $instance['title'] : __('Recent Comments', 'bigboom'); /** This filter is documented in wp-includes/default-widgets.php */ $title = apply_filters('widget_title', $title, $instance, $this->id_base); $number = absint($instance['number']); if (!$number) { $number = 5; } /** * Filter the arguments for the Recent Comments widget. * * @since 3.4.0 * * @see WP_Comment_Query::query() for information on accepted arguments. * * @param array $comment_args An array of arguments used to retrieve the recent comments. */ $comments = get_comments(apply_filters('widget_comments_args', array('number' => $number, 'status' => 'approve', 'post_status' => 'publish'))); echo $args['before_widget']; if ($title) { echo $args['before_title'] . esc_html($title) . $args['after_title']; } echo '<ul id="recentcomments">'; if ($comments) { // Prime cache for associated posts. (Prime post term cache if we need it for permalinks.) $post_ids = array_unique(wp_list_pluck($comments, 'comment_post_ID')); _prime_post_caches($post_ids, strpos(get_option('permalink_structure'), '%category%'), false); foreach ((array) $comments as $comment) { echo '<li class="recentcomments">'; /* translators: comments widget: 1: comment author, 2: post link */ echo sprintf(_x('Posted by: %1$s', 'widgets', 'bigboom'), '<span class="comment-author-link">' . get_comment_author_link() . '</span>'); bigboom_content_limit($comment->comment_content, intval($instance['length']), ''); echo '</li>'; } } echo '</ul>'; echo $args['after_widget']; }
/** * Posts carousel shortcode * * @param array $atts * @param string $content * * @return string */ function posts_carousel($atts, $content) { $atts = shortcode_atts(array('title' => '', 'total' => '12', 'categories' => '', 'order_by' => '', 'order' => '', 'excerpt_length' => '', 'hide_read_more' => '', 'read_more_text' => __('Read More', 'bigboom'), 'number' => '3', 'auto_play' => '', 'hide_navigation' => '', 'class_name' => ''), $atts); $output = array(); $number = intval($atts['number']); $number = $number ? $number : '4'; $id = uniqid('posts-carousel-'); $this->l10n['postsCarousel'][$id] = array('number' => $number, 'autoplay' => $atts['auto_play'] ? $atts['auto_play'] : 'false', 'navigation' => $atts['hide_navigation'] ? $atts['hide_navigation'] : 'true'); $query_args = array('orderby' => $atts['order_by'], 'order' => $atts['order'], 'posts_per_page' => $atts['total'], 'post_type' => 'post', 'ignore_sticky_posts' => true); if (!empty($atts['categories'])) { $query_args['category__in'] = $atts['categories']; } $query = new WP_Query($query_args); while ($query->have_posts()) { $query->the_post(); $src = bigboom_get_image(array('size' => 'blog-thumb-tiny', 'format' => 'src', 'echo' => false)); $class_thumb = 'no-thumb'; $article = array(); if ($src) { $class_thumb = ''; $article[] = sprintf('<a class="post-thumb" href="%s" title="%s"><img src="%s" alt="%s"></a>', esc_url(get_permalink()), the_title_attribute('echo=0'), esc_url($src), the_title_attribute('echo=0')); } $article[] = sprintf('<div class="post-text"><a class="post-title" href="%s" title="%s" rel="bookmark">%s</a>', esc_url(get_permalink()), the_title_attribute('echo=0'), get_the_title()); $article[] = bigboom_content_limit(get_the_excerpt(), intval($atts['excerpt_length']), '', false); if (!$atts['hide_read_more']) { $article[] = sprintf('<a class="read-more" href="%s" title="%s" rel="bookmark">%s<i class="fa fa-arrow-circle-right"></i></a>', esc_url(get_permalink()), the_title_attribute('echo=0'), $atts['read_more_text']); } $output[] = sprintf('<div class="bb-post %s">%s</div></div>', esc_attr($class_thumb), implode('', $article)); } wp_reset_postdata(); $heading = ''; if ($atts['title']) { $heading = sprintf('<h2 class="section-heading">%s</h2>', $atts['title']); } else { $atts['class_name'] .= ' no-title'; } if ($atts['hide_navigation']) { $atts['class_name'] .= ' no-owl-controls'; } return sprintf('<div id="%s" class="bb-posts-owl-carousel %s">%s<div class="bb-owl-list">%s</div></div>', esc_attr($id), esc_attr($atts['class_name']), $heading, implode('', $output)); }
/** * Display widget * * @param array $args Sidebar configuration * @param array $instance Widget settings * * @return void */ function widget($args, $instance) { $instance = wp_parse_args($instance, $this->defaults); extract($args); $query_args = array('posts_per_page' => $instance['limit'], 'post_type' => 'post', 'ignore_sticky_posts' => true); if (!empty($instance['cat']) && is_array($instance['cat'])) { $query_args['category__in'] = $instance['cat']; } $query = new WP_Query($query_args); if (!$query->have_posts()) { return; } echo $before_widget; if ($title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base)) { echo $before_title . esc_html($title) . $after_title; } $class = $instance['thumb'] ? '' : 'no-thumbnail'; $class .= $instance['thumb_left'] ? 'thumb-left' : ''; while ($query->have_posts()) { $query->the_post(); ?> <article class="recent-post <?php echo esc_attr($class); ?> "> <?php if ($instance['thumb']) { $src = bigboom_get_image(array('size' => $instance['thumb_size'], 'format' => 'src', 'echo' => false)); if ($src) { printf('<a class="widget-thumb" href="%s" title="%s"><img src="%s" alt="%s"></a>', esc_url(get_permalink()), the_title_attribute('echo=0'), esc_url($src), the_title_attribute('echo=0')); } } ?> <div class="post-text"> <a class="post-title" href="<?php the_permalink(); ?> " title="<?php the_title_attribute(); ?> " rel="bookmark"><?php the_title(); ?> </a> <?php if ($instance['excerpt']) { echo bigboom_content_limit(get_the_excerpt(), intval($instance['limit']), ''); } if ($instance['date']) { echo '<time class="post-date" datetime="' . esc_attr(get_the_time('c')) . '">' . get_the_time("d F Y") . '</time>'; } if ($instance['comments']) { $comments_count = wp_count_comments(get_the_ID()); echo '<span class="post-comments">' . sprintf(__('%s Comments', 'bigboom'), intval($comments_count->total_comments)) . '</span>'; } if ($instance['readmore']) { echo '<a class="read-more" href="' . esc_url(get_permalink()) . '" title="' . the_title_attribute('echo=0') . '" rel="bookmark">' . $instance['more_text'] . '</a>'; } ?> </div> </article> <?php } wp_reset_postdata(); echo $after_widget; }