* * @package deTube * @subpackage Template * @since deTube 1.0 */ ?> <?php $args = (array) get_option('dp_cat_featured'); // If user set 'Post Number' to 0 or leave it empty in theme options, return. if (empty($args['posts_per_page'])) { return; } $args['posts_per_page'] = 14; $args['current_cat'] = true; $args = dp_parse_query_args($args); $query = new WP_Query($args); if ($query->have_posts()) { // Load scripts only when needed wp_enqueue_script('jquery-carousel'); // Get items $items = ''; $i = 0; while ($query->have_posts()) { $query->the_post(); $thumb_html = dp_thumb_html('custom-small', '', '', false); // Build classname $classes = array(); $classes[] = is_video() ? 'item-video' : 'item-post'; $class = implode(' ', $classes); $items .= '<li class="' . $class . '">' . $thumb_html . '</li>';
/** * Output a Section Box * * @since deTube 1.0 */ function dp_section_box($args = array()) { $defaults = array('post_type' => 'post', 'cat' => '', 'taxonomies' => array(), 'view' => 'grid-small', 'title' => '', 'link' => '', 'post__in' => '', 'posts_per_page' => '', 'hide_if_empty' => false); $args = wp_parse_args($args, $defaults); extract($args); $posts_per_page = absint($posts_per_page); // Set default posts number if no specified if (empty($posts_per_page)) { if ($view == 'grid-mini') { $posts_per_page = 8; } elseif ($view == 'grid-small') { $posts_per_page = 6; } elseif ($view == 'grid-medium') { $posts_per_page = 4; } elseif ($view == 'list-small') { $posts_per_page = 3; } elseif ($view == 'list-medium') { $posts_per_page = 2; } elseif ($view == 'list-large') { $posts_per_page = 1; } } $args['posts_per_page'] = $posts_per_page; $args = dp_parse_query_args($args); $query = new WP_Query($args); // Output nothing if there is no posts if (!$query->have_posts() && $hide_if_empty) { return; } // Output content before section if (!empty($before)) { echo '<div class="section-box section-before rich-content">' . do_shortcode(wp_kses_stripslashes($before)) . '</div><!-- end .section-box -->'; } // Section box begin echo '<div class="section-box">'; global $section_view; $section_view = $view; // Get term name as title $term = ''; $cat = $taxonomies['category']; if ($cat) { $term = get_term($cat, 'category'); } if (empty($title) && $term) { $title = $term->name; } if (empty($link) && $term) { $link = get_term_link($term, 'category'); } $title = '<span class="name">' . $title . '</span>'; // Add link to title and more $more = ''; if ($link) { $title = '<a class="name-link" href="' . $link . '">' . $title . '</a>'; $more = '<a class="more-link" href="' . $link . '"><span>' . __('More', 'dp') . ' <i class="mini-arrow-right"></i></span></a>'; } // Output section header echo '<div class="section-header"><h2 class="section-title">' . $title . '</h2>' . $more . '</div>'; // Output section content echo '<div class="section-content ' . $view . '"><div class="nag cf">'; while ($query->have_posts()) { $query->the_post(); get_template_part('item-video'); } wp_reset_query(); echo '</div></div><!-- end .section-content -->'; // End section box echo '</div><!-- end .section-box -->'; // Output content after section if (!empty($after)) { echo '<div class="section-box section-after rich-content">' . do_shortcode(wp_kses_stripslashes($after)) . '</div><!-- end .section-box -->'; } }
function widget($args, $instance) { $cache = wp_cache_get('dp_widget_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; } $style = isset($instance['style']) ? $instance['style'] : 'list'; extract($args); ob_start(); $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts', 'dp') : $instance['title'], $instance, $this->id_base); $query_args = $instance; $query_args['no_found_rows'] = true; $query_args = dp_parse_query_args($query_args); $r = new WP_Query(apply_filters('dp_widget_posts_args', $query_args)); if ($r->have_posts()) { ?> <?php echo $before_widget; ?> <?php if ($title) { echo $before_title . $title . $after_title; } ?> <ul class="<?php echo 'post-' . $style; ?> "> <?php while ($r->have_posts()) { $r->the_post(); $item_format = is_video() ? 'video' : 'post'; ?> <li class="item cf <?php echo 'item-' . $item_format; ?> "> <?php $image_size = $style == 'list-full' ? 'custom-medium' : 'custom-small'; dp_thumb_html($image_size); ?> <div class="data"> <h4 class="entry-title"><a href="<?php the_permalink(); ?> " title="<?php echo esc_attr(get_the_title()); ?> "><?php the_title(); ?> </a></h4> <p class="meta"> <span class="author"><?php _e('Added by', 'dp'); ?> <?php the_author_posts_link(); ?> </span> <span class="time"><?php printf(__('%s ago', 'dp'), human_time(get_the_time('U'))); ?> </span> </p> <p class="stats"><?php echo dp_get_post_stats(); ?> </p> </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('dp_widget_posts', $cache, 'widget'); }