Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 = '';
- if(!empty($taxonomies['category']))
- $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');
- endwhile;
- wp_reset_postdata();
- echo '</div></div><!-- end .section-content -->';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement