Advertisement
Guest User

Untitled

a guest
Dec 11th, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. function dp_section_box($args = array()) {
  2. $defaults = array(
  3. 'post_type' => 'post',
  4. 'cat' => '',
  5. 'taxonomies' => array(),
  6. 'view' => 'grid-small',
  7. 'title' => '',
  8. 'link' => '',
  9. 'post__in' => '',
  10. 'posts_per_page' => '',
  11. 'hide_if_empty' => false
  12. );
  13. $args = wp_parse_args($args, $defaults);
  14. extract($args);
  15.  
  16. $posts_per_page = absint($posts_per_page);
  17. // Set default posts number if no specified
  18. if(empty($posts_per_page)) {
  19. if($view == 'grid-mini')
  20. $posts_per_page = 8;
  21. elseif($view == 'grid-small')
  22. $posts_per_page = 6;
  23. elseif($view == 'grid-medium')
  24. $posts_per_page = 4;
  25. elseif($view == 'list-small')
  26. $posts_per_page = 3;
  27. elseif($view == 'list-medium')
  28. $posts_per_page = 2;
  29. elseif($view == 'list-large')
  30. $posts_per_page = 1;
  31. }
  32. $args['posts_per_page'] = $posts_per_page;
  33.  
  34. $args = dp_parse_query_args($args);
  35. $query = new WP_Query($args);
  36.  
  37. // Output nothing if there is no posts
  38. if(!$query->have_posts() && $hide_if_empty)
  39. return;
  40.  
  41. // Output content before section
  42. if(!empty($before))
  43. echo '<div class="section-box section-before rich-content">'. do_shortcode(wp_kses_stripslashes($before)).'</div><!-- end .section-box -->';
  44.  
  45. // Section box begin
  46. echo '<div class="section-box">';
  47.  
  48. global $section_view;
  49. $section_view = $view;
  50.  
  51. // Get term name as title
  52. $term = '';
  53. $cat = '';
  54. if(!empty($taxonomies['category']))
  55. $cat = $taxonomies['category'];
  56. if($cat)
  57. $term = get_term($cat, 'category');
  58. if(empty($title) && $term)
  59. $title = $term->name;
  60. if(empty($link) && $term)
  61. $link = get_term_link($term, 'category');
  62.  
  63. $title = '<span class="name">'.$title.'</span>';
  64.  
  65. // Add link to title and more
  66. $more = '';
  67. if($link) {
  68. $title = '<a class="name-link" href="'.$link.'">'.$title.'</a>';
  69. $more = '<a class="more-link" href="'.$link.'"><span>'.__('More', 'dp').' <i class="mini-arrow-right"></i></span></a>';
  70. }
  71.  
  72. // Output section header
  73. echo '<div class="section-header"><h2 class="section-title">'.$title.'</h2>'.$more.'</div>';
  74.  
  75. // Output section content
  76. echo '<div class="section-content '.$view.'"><div class="nag cf">';
  77. while ($query->have_posts()) : $query->the_post();
  78. get_template_part('item-video');
  79. endwhile;
  80.  
  81. wp_reset_postdata();
  82.  
  83. echo '</div></div><!-- end .section-content -->';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement