/** * Outputs the content of the widget. * * @author Richard Tape * @package themeists_latest_blog_posts * @since 1.0 * @param (array) $args - The array of form elements * @param (array) $instance - The saved options from the widget controls * @return None */ function widget($args, $instance) { extract($args, EXTR_SKIP); echo $before_widget; //Get vars $title = apply_filters('widget_title', empty($instance['title']) ? false : $instance['title'], $instance, self::slug); $subtitle = apply_filters('widget_title', empty($instance['subtitle']) ? false : $instance['subtitle'], $instance, self::slug); //How many posts to show $num_to_show = isset($instance['num_to_show']) ? intval($instance['num_to_show']) : 3; //What post type to show $type_to_show = isset($instance['type_to_show']) ? $instance['type_to_show'] : 'post'; //Whether to limit to a specific taxonomy or not $tax_to_show = isset($instance['tax_to_show']) ? $instance['tax_to_show'] : false; //Whether to limit to a specific taxonomy term or not $term_to_show = isset($instance['term_to_show']) ? $instance['term_to_show'] : false; //Show a "read more" button $show_more_button = isset($instance['show_more_button']) ? $instance['show_more_button'] : false; $button_text = isset($instance['button_text']) ? strip_tags($instance['button_text']) : false; $button_link = isset($instance['button_link']) ? $instance['button_link'] : false; //Show the thumbnail? $show_thumbnail = isset($instance['show_thumbnail']) ? $instance['show_thumbnail'] : false; //Show the number of comments? $show_comments = isset($instance['show_comments']) ? $instance['show_comments'] : false; //Show date $show_date = isset($instance['show_date']) ? $instance['show_date'] : false; //Show author $show_author = isset($instance['show_author']) ? $instance['show_author'] : false; //If our like plugin is activated, show the option to show the number of likes for the post $show_likes = isset($instance['show_likes']) ? $instance['show_likes'] : false; //Now we have our values, we are going to run them through some custom filters so we can modify the output //externally ?> <?php echo apply_filters('themeists_widget_lbp_container_open', '<div class="row">'); ?> <?php if ($title) { echo $before_title . $title . $after_title; } ?> <?php /* Build the loop query based on the widget settings ================================================= */ $query_args = array('posts_per_page' => $num_to_show, 'post_status' => 'publish', 'ignore_sticky_posts' => 1); //If we have a post type selected, add it to the args if ($type_to_show) { $query_args['post_type'] = $type_to_show; } //If we have a taxonomy selected, add that to the args if ($tax_to_show && $term_to_show) { $query_args['tax_query'] = array(array('taxonomy' => $tax_to_show, 'field' => 'slug', 'terms' => $term_to_show)); } //Get ourselves a query object **don't forget to run wp_reset_postdata()** $lbp = new WP_Query(apply_filters('themeists_widget_lbp_query_args', $query_args)); /* =================================================================== Now the loop is built, we need to output our markup. We check if the current theme has a template file for this widget. If it does, we use that, otherwise we output the default widget markup. =================================================================== */ if ($lbp->have_posts()) { if (locate_template('/templates/latest_blog_posts_widget.php') != '') { include locate_template('/templates/latest_blog_posts_widget.php'); } else { if ($show_more_button == 1) { echo apply_filters('themeists_widget_lbp_more_button', ''); } echo apply_filters('themeists_widget_lbp_list_open', "<ul class='show_{$num_to_show}'>", $query_args, $num_to_show); while ($lbp->have_posts()) { $lbp->the_post(); ?> <li class="lbp_widget_post_<?php echo get_the_ID(); ?> columns <?php echo incipio_convert_number_to_words(12 / $num_to_show); ?> "> <?php if ($show_thumbnail == 1) { ?> <div class="hover_block"> <a href="<?php the_permalink(); ?> " title="<?php the_title(); ?> " class="lbp_thumb"> <div class="box"> <?php the_post_thumbnail(apply_filters('themeists_widget_lbp_thumbnail_size', 'lbp_thumb')); ?> <div class="onhover"> <p> <span> <?php echo apply_filters('themeists_lbp_read_more_text', 'Read More'); ?> </span> </p> </div><!-- .details --> </div> </a> </div><!-- .mosaic-block --> <?php } ?> <h4 class="<?php echo apply_filters('themeists_widget_lbp_post_title_classes', 'widget_post_title'); ?> "> <a href="<?php the_permalink(); ?> " title="<?php the_title(); ?> "><?php the_title(); ?> </a> </h4> <div class="<?php echo apply_filters('themeists_widget_lbp_post_excerpt_classes', 'widget_post_excerpt'); ?> "> <?php the_excerpt(); ?> </div><!-- .widget_post_excerpt --> <?php if ($show_comments == 1 || $show_date == 1 || $show_author == 1 || $show_likes == 1) { ?> <ul class="<?php echo apply_filters('themeists_widget_lbp_post_meta_classes', 'widget_post_meta'); ?> "> <?php if ($show_comments == 1) { ?> <li class="lbp_comments li_with_icon"> <a href="<?php the_permalink(); ?> #comments" title="<?php the_title(); ?> "> <?php comments_number(__('0 comments', THEMENAME), __('1 comment', THEMENAME), __('% comments', THEMENAME)); ?> </a> </li> <?php } ?> <?php if ($show_date == 1) { ?> <li class="lbp_date"> <?php the_time('M j, Y'); ?> </li> <?php } ?> <?php if ($show_author == 1) { ?> <li class="lbp_author li_with_icon"> <?php the_author_posts_link(); ?> </li> <?php } ?> <?php if ($show_likes == 1) { ?> <li class="lbp_likes"> <?php ThemeistsLikeThis::printLikes(get_the_ID()); ?> </li> <?php } ?> </ul><!-- .widget_post_meta --> <?php } ?> </li> <?php } wp_reset_postdata(); echo apply_filters('themeists_widget_lbp_list_close', '</ul>', $query_args); } } ?> <?php echo apply_filters('themeists_widget_lbp_container_close', '</div>'); ?> <?php echo $after_widget; }
?> <li class="lbp_author li_with_icon"> <?php the_author_posts_link(); ?> </li> <?php } ?> <?php if ($show_likes == 1) { ?> <li class="lbp_likes"> <?php ThemeistsLikeThis::printLikes(get_the_ID()); ?> </li> <?php } ?> </ul><!-- .widget_post_meta --> <?php } ?> </li> <?php