Advertisement
Guest User

partial-sliders.php

a guest
Nov 28th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.08 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Partial Template - Display the featured slider and the blocks
  5.  */
  6.  
  7. // using revolution slider? output and return
  8. if (Bunyad::posts()->meta('featured_slider') == 'rev-slider' && function_exists('putRevSlider')) {
  9.    
  10.     echo '<div class="main-featured"><div class="wrap cf"><div class="row"><div class="col-8">'
  11.         . do_shortcode('[rev_slider ' . esc_attr(Bunyad::posts()->meta('slider_rev')) .']')
  12.         . '</div><div class="col-4">'
  13.         . dynamic_sidebar('slider-right')
  14.         . '</div></div></div></div>';
  15.    
  16.     return;
  17. }
  18.  
  19. // configuration vars
  20. $data_vars = array(
  21.     'data-animation-speed="'. intval(Bunyad::options()->slider_animation_speed) . '"',
  22.     'data-animation="' . esc_attr(Bunyad::options()->slider_animation) . '"',
  23.     'data-slide-delay="' . esc_attr(Bunyad::options()->slider_slide_delay) . '"',
  24. );
  25.  
  26. $data_vars  = implode(' ', $data_vars);
  27. $main_limit = (Bunyad::posts()->meta('slider_number') ? intval(Bunyad::posts()->meta('slider_number')) : 5);
  28.  
  29. // get latest featured posts
  30. $args = apply_filters(
  31.     'bunyad_block_query_args',
  32.     array('meta_key' => '_bunyad_featured_post', 'meta_value' => 1, 'order' => 'date', 'posts_per_page' => $main_limit + 3, 'ignore_sticky_posts' => 1),
  33.     'slider'
  34. );
  35.  
  36. // limited to tag?
  37. if (Bunyad::posts()->meta('slider_tags')) {
  38.     $args['tag_slug__in'] = explode(',', Bunyad::posts()->meta('slider_tags'));
  39. }
  40.  
  41. // manual post ids?
  42. if (Bunyad::posts()->meta('slider_posts')) {
  43.     $args['post__in'] = explode(',', Bunyad::posts()->meta('slider_posts'));
  44. }
  45.  
  46. /**
  47.  * Posts grid generated from a category or a tag? (right side of slider)
  48.  */
  49. $limit_cat = Bunyad::options()->featured_right_cat;
  50. $limit_tag = Bunyad::options()->featured_right_tag;
  51.  
  52. if (!empty($limit_cat)) {
  53.    
  54.     $args['posts_per_page'] = $main_limit;
  55.     $grid_query = new WP_Query(apply_filters('bunyad_block_query_args', array('cat' => $limit_cat, 'posts_per_page' => 3), 'slider_grid'));
  56. }
  57. else if (!empty($limit_tag)) {
  58.    
  59.     $args['posts_per_page'] = $main_limit;
  60.     $grid_query = new WP_Query(apply_filters('bunyad_block_query_args', array('tag' => $limit_tag, 'posts_per_page' => 3), 'slider_grid'));
  61. }
  62.  
  63. /**
  64.  * Category slider?
  65.  */
  66. if (is_category()) {
  67.     $cat = get_query_var('cat');
  68.     $meta = Bunyad::options()->get('cat_meta_' . $cat);
  69.    
  70.     // slider not enabled? quit!
  71.     if (empty($meta['slider'])) {
  72.         return;
  73.     }
  74.        
  75.     $args['cat'] = $cat;
  76.    
  77.     // latest posts?
  78.     if ($meta['slider'] == 'latest') {
  79.         unset($args['meta_key'], $args['meta_value']);
  80.     }
  81.     $main_limit = 1;
  82. }
  83.  
  84. /**
  85.  * Main slider posts query
  86.  */
  87.  
  88. // use latest posts?
  89. if (Bunyad::posts()->meta('featured_slider') == 'default-latest') {
  90.     unset($args['meta_key'], $args['meta_value']);
  91. }
  92.  
  93. $query = new WP_Query($args);
  94.  
  95. if (!$query->have_posts()) {
  96.     return;
  97. }
  98.  
  99. // Use rest of the 3 posts for grid if not post grid is not using
  100. // any category or tag. Create reference for to main query.
  101. if (empty($grid_query) && $query->found_posts > $main_limit) {
  102.     $grid_query = &$query;
  103. }
  104.  
  105.  
  106. $i = $z = 0; // loop counters
  107.  
  108. ?>
  109.    
  110.     <div class="main-featured">
  111.         <div class="wrap cf">
  112.        
  113.         <div class="row">
  114.             <div class="slider frame flexslider col-8" <?php echo $data_vars; ?>>
  115.                 <ul class="slides">
  116.                
  117.                 <?php while ($query->have_posts()): $query->the_post(); ?>
  118.                    
  119.                     <li>
  120.                         <a href="<?php the_permalink(); ?>" class="image-link"><?php the_post_thumbnail('main-slider', array('alt' => esc_attr(get_the_title()), 'title' => '')); ?></a>                   
  121.    
  122.                         <?php
  123.                         // custom label selected?
  124.                         if (($cat_label = Bunyad::posts()->meta('cat_label'))) {
  125.                             $cat = get_category($cat_label);
  126.                         }
  127.                         else {
  128.                             $cat = current(get_the_category());                    
  129.                         }
  130.                         ?>
  131.                         <a href="<?php echo get_category_link($cat->term_id); ?>" class="cat cat-title cat-<?php echo $cat->cat_ID; ?>"><?php echo esc_html($cat->cat_name); ?></a>
  132.                        
  133.                         <div class="caption">
  134.  
  135.                             <time class="the-date" datetime="<?php echo esc_attr(get_the_time('c')); ?>"><?php echo esc_html(get_the_date()); ?></time>
  136.                            
  137.                             <h3><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
  138.    
  139.                         </div>                 
  140.                        
  141.                     </li>
  142.                    
  143.                 <?php
  144.                         if ($i++ == ($main_limit - 1)) {
  145.                            
  146.                             // give a chance to loop_end hook to run because we are breaking - required for duplicates prevention
  147.                             $query->have_posts();
  148.                             break;
  149.                         }
  150.                    
  151.                     endwhile; //rewind_posts();
  152.                 ?>
  153.            
  154.                 </ul>
  155.                
  156.                 <div class="pages" data-number="<?php echo esc_attr($main_limit); ?>">
  157.                
  158.                 <?php foreach (range(1, $main_limit) as $page): ?>
  159.                     <a href="#"></a>
  160.                 <?php endforeach; ?>
  161.                
  162.                 </div>
  163.                
  164.                
  165.             </div> <!-- .flexslider -->
  166.        
  167.             <div class="blocks col-4">
  168.            
  169.             <?php if (!empty($grid_query) && $grid_query->have_posts()): ?>
  170.            
  171.                 <?php while ($grid_query->have_posts()): $grid_query->the_post(); $z++;
  172.                
  173.                         if (!has_post_thumbnail()) {
  174.                             continue;
  175.                         }
  176.                        
  177.                         // custom label selected?              
  178.                         if (($cat_label = Bunyad::posts()->meta('cat_label'))) {
  179.                             $category = get_category($cat_label);
  180.                         }
  181.                         else {
  182.                             $category = current(get_the_category());                       
  183.                         }
  184.                 ?>
  185.                
  186.                 <article class="<?php echo ($z == 1 ? 'large' : ($z == 2 ? 'small' : 'small last')); ?>">
  187.                      
  188.                 <?php if ($z == 1): ?>
  189.                      <span class="cat cat-title cat-<?php echo $category->cat_ID; ?>"><a href="<?php echo esc_url(get_category_link($category)); ?>"><?php echo esc_html($category->name); ?></a></span>
  190.                 <?php endif; ?>
  191.                      
  192.                      <a href="<?php the_permalink(); ?>" class="image-link"><?php
  193.                         the_post_thumbnail(($z == 1 ? 'main-block' : 'slider-small'), array('alt' => esc_attr(get_the_title()), 'title' => '')); ?></a>
  194.                      
  195.                      <h3><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
  196.                    
  197.                 </article>
  198.                
  199.                
  200.                 <?php endwhile; ?>
  201.                
  202.             <?php endif; // end post count check ?>            
  203.             </div>
  204.            
  205.         </div> <!-- .row -->
  206.  
  207.         <?php wp_reset_query(); ?>
  208.  
  209.         </div> <!--  .wrap  -->
  210.     </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement