/** * 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($instance); $query_args = array('posts_per_page' => $limit, 'post_status' => 'publish', 'post_type' => 'post', 'ignore_sticky_posts' => true); if (!empty($cat) && is_array($cat)) { $query_args['category__in'] = $cat; } $query = new WP_Query($query_args); if (!$query->have_posts()) { return; } extract($args); echo $before_widget; if ($title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base)) { echo $before_title . $title . $after_title; } while ($query->have_posts()) { $query->the_post(); $class = $thumb ? '' : ' fitwp-list'; ?> <article class="fitwp-recent-post <?php echo $class; ?> "> <?php if ($thumb) { $src = constructent_post_thumbnail_src('constructent-widget-thumb'); if (!$src) { $src = $thumb_default; } if ($src) { printf('<a class="fitwp-thumb" href="%s" title="%s"><img src="%s" alt="%s"></a>', get_permalink(), the_title_attribute('echo=0'), $src, the_title_attribute('echo=0')); } } ?> <div class="fitwp-text"> <a class="fitwp-title" href="<?php the_permalink(); ?> " title="<?php printf(esc_attr__('Permalink to %s', 'constructent'), the_title_attribute('echo=0')); ?> " rel="bookmark"><?php the_title(); ?> </a> <?php if ($date) { echo '<time class="fitwp-date" datetime="' . esc_attr(get_the_time('c')) . '">' . esc_html(get_the_time($date_format)) . '</time>'; } if ($comments) { echo '<span class="fitwp-comments">' . sprintf(esc_html__('%s Comments', 'constructent'), get_comments_number()) . '</span>'; } if ($excerpt) { $more = $readmore ? $readmore_text : ''; echo '<div class="fitwp-excerpt">' . constructent_content_limit($length, $more, false) . '</div>'; } ?> </div> </article> <?php } wp_reset_postdata(); echo $after_widget; }
/** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments * @param array $instance Saved values from database * * @return void */ function widget($args, $instance) { $instance = wp_parse_args($instance, $this->defaults); extract($instance); extract($args); echo $before_widget; echo '<div class="fitwp-tabs">'; echo '<ul class="fitwp-tabs-nav">'; if ($popular_show) { echo "<li><a href='#'>{$popular_title}</a></li>"; } if ($recent_show) { echo "<li><a href='#'>{$recent_title}</a></li>"; } if ($comments_show) { echo "<li><a href='#'>{$comments_title}</a></li>"; } echo '</ul>'; ?> <div class="fitwp-tabs-content"> <?php if ($popular_show) { ?> <div class="fitwp-tab fitwp-active"> <?php $popular_posts = new WP_Query(array('posts_per_page' => $popular_limit, 'orderby' => 'comment_count', 'order' => 'DESC')); while ($popular_posts->have_posts()) { $popular_posts->the_post(); $class = $popular_thumb ? '' : ' fitwp-list'; ?> <article class="fitwp-popular-post <?php echo $class; ?> "> <?php if ($popular_thumb) { $src = constructent_post_thumbnail_src('constructent-widget-thumb'); if (!$src) { $src = $popular_thumb_default; } if ($src) { printf('<a class="fitwp-thumb" href="%s" title="%s"><img src="%s" alt="%s"></a>', get_permalink(), the_title_attribute('echo=0'), esc_url($src), the_title_attribute('echo=0')); } } ?> <div class="fitwp-text"> <a class="fitwp-title" href="<?php the_permalink(); ?> " title="<?php printf(esc_attr__('Permalink to %s', 'constructent'), the_title_attribute('echo=0')); ?> " rel="bookmark"><?php the_title(); ?> </a> <?php if ($popular_date) { echo '<time class="fitwp-date" datetime="' . esc_attr(get_the_time('c')) . '">' . esc_html(get_the_time($popular_date_format)) . '</time>'; } if ($popular_comments) { echo '<span class="fitwp-comments">' . sprintf(esc_html__('%s Comments', 'constructent'), get_comments_number()) . '</span>'; } ?> </div> </article> <?php } wp_reset_postdata(); ?> </div> <?php } ?> <?php if ($recent_show) { ?> <div class="fitwp-tab"> <?php the_widget('Constructent_Widget_Recent_Posts', array('limit' => $recent_limit, 'thumb' => $recent_thumb, 'thumb_default' => $recent_thumb_default, 'date' => $recent_date, 'comments' => $recent_comments, 'date_format' => $recent_date_format), array('before_widget' => '', 'after_widget' => '')); ?> </div> <?php } ?> <?php if ($comments_show) { echo '<div class="fitwp-tab fitwp-comment-tab">'; $comments = get_comments(array('status' => 'approve', 'number' => $comments_limit)); foreach ($comments as $comment) { echo sprintf('<div class="fitwp-comment"> <p class="fitwp-comment-summary">%s <span class="fitwp-author-comment">%s %s</span></p> <span class="fitwp-post-comment">%s <a href="%s" title="%s">%s</a></span> </div>', wp_trim_words(strip_tags($comment->comment_content), 10), esc_html__('by', 'constructent'), $comment->comment_author, esc_html__('on', 'constructent'), get_comments_link($comment->comment_post_ID), esc_attr(get_the_title($comment->comment_post_ID)), wp_trim_words(strip_tags(get_the_title($comment->comment_post_ID)), 7)); } echo '</div>'; } ?> </div> <?php echo '</div>'; echo $after_widget; }