Guest User

Untitled

a guest
Nov 20th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.94 KB | None | 0 0
  1.  
  2. if ( ! function_exists( 'kleo_posts_carousel' ) ) {
  3.     function kleo_posts_carousel( $atts, $content = null ) {
  4.             extract( shortcode_atts( array(
  5.                 'cat' => 'all',
  6.                 'limit' => 9,
  7.                 'post_types' => 'post',
  8.                 'post_formats' => 'image,gallery,video',
  9.                 'class' => ''
  10.                 ), $atts));
  11.  
  12.             $output = '<div class="kleo-carousel '.$class.'">'.
  13.                     '<p>
  14.                             <span class="right hide-for-small">
  15.                                     <a href="#" class="story-prev"><i class="icon-circle-arrow-left icon-large"></i></a>&nbsp;
  16.                                     <a href="#" class="story-next"><i class="icon-circle-arrow-right icon-large"></i></a>
  17.                             </span>
  18.                     </p>
  19.                     <div class="carousel-stories responsive">
  20.                         <ul class="feature-stories">';
  21.        
  22.        
  23.         $args = array();
  24.         if ( (int) $cat != 0 ) {
  25.             $args['cat'] = $cat;
  26.         }
  27.         if ( (int) $limit != 0 ) {
  28.             $args['posts_per_page'] = $limit;
  29.         }
  30.        
  31.         $args['post_type'] = explode(',', $post_types);
  32.        
  33.         $formats = explode( ',', $post_formats );
  34.         if ( is_array( $formats ) && ! in_array( 'all', $formats ) ) {
  35.             foreach( $formats as $format ) {
  36.                 $terms_query[] = 'post-format-' . $format;
  37.             }
  38.             $args['tax_query'] = array(
  39.                 array(
  40.                 'taxonomy' => 'post_format',
  41.                 'field' => 'slug',
  42.                 'terms' => $terms_query
  43.                 )
  44.             );
  45.         }
  46.        
  47.         $latestPosts = new WP_Query( apply_filters( 'kleo_posts_carousel_args', $args ) );
  48.  
  49.         while ( $latestPosts->have_posts() ) : $latestPosts->the_post();
  50.            
  51.             switch (get_post_format()) {
  52.                 case 'video':
  53.                     $video = get_cfield('embed');
  54.                     if (!empty($video))
  55.                     {
  56.                         $output .= '<li>';
  57.                         $output .= wp_oembed_get($video);
  58.  
  59.                         $output .= '<h4>'.get_the_title().'</h4>';
  60.                         $output .= '<p>'.  word_trim(get_the_excerpt(), 15, '...').'</p>';
  61.                         $output .= '<p><a href="'.  get_permalink() .'" class="small button radius secondary"><i class="icon-angle-right"></i> '.__("READ MORE", 'kleo_framework').'</a></p>';
  62.                         $output .= '</li>';
  63.                     }
  64.                                        
  65.                     break;
  66.                    
  67.                 case 'gallery':
  68.                     $slides = get_cfield( 'slider' );
  69.                     if ( ! empty( $slides ) )
  70.                     {
  71.                         $output .= '<li>';
  72.                         $output .= '<div class="blog-slider">';
  73.  
  74.                         foreach($slides as $slide)
  75.                         {
  76.                             if (get_attachment_id_from_url($slide))
  77.                             {
  78.                                 $thumb_array = image_downsize( get_attachment_id_from_url($slide), 'blog_carousel' );
  79.                                 $thumb_path = $thumb_array[0];
  80.                             }
  81.                             else
  82.                             {
  83.                                 $thumb_path = $slide;
  84.                             }
  85.                                
  86.                             $output .= '<div data-thumb="'.$slide.'">';
  87.                             $output .= '<img src="'.$thumb_path.'" alt="">';
  88.                             $output .= '</div>';
  89.                         }
  90.                         $output .= '</div><!--end blog-slider-->';
  91.                        
  92.                         $output .= '<h4>'.get_the_title().'</h4>';
  93.                         $output .= '<p>'.  word_trim(get_the_excerpt(), 15, '...').'</p>';
  94.                         $output .= '<p><a href="'.  get_permalink() .'" class="small button radius secondary"><i class="icon-angle-right"></i> '.__("READ MORE", 'kleo_framework').'</a></p>';
  95.                         $output .= '</li>';
  96.                     }
  97.                    
  98.                     break;
  99.                    
  100.                 case 'image':
  101.                     if (get_post_thumbnail_id())
  102.                     {  
  103.                         $output .= '<li>';
  104.                         $output .= '<div class=""><a class="imagelink" href="'.  get_permalink().'">';
  105.                         $output .= '<span class="read"><i class="icon-'.apply_filters('kleo_img_rounded_icon','heart').'"></i></span>';
  106.                         $output .= get_the_post_thumbnail(null,'blog_carousel');
  107.                         $output .= '</a></div>';
  108.                        
  109.                         $output .= '<h4>'.get_the_title().'</h4>';
  110.                         $output .= '<p>'.  word_trim(get_the_excerpt(), 15, '...').'</p>';
  111.                         $output .= '<p><a href="'.  get_permalink() .'" class="small button radius secondary"><i class="icon-angle-right"></i> '.__("READ MORE", 'kleo_framework').'</a></p>';
  112.                         $output .= '</li>';
  113.                    
  114.                     }
  115.                     break;
  116.                 default:
  117.                         $output .= '<li>';  
  118.                         if (get_post_thumbnail_id())
  119.                         {  
  120.                             $output .= '<div class=""><a class="imagelink" href="'.  get_permalink().'">';
  121.                             $output .= '<span class="read"><i class="icon-'.apply_filters('kleo_img_rounded_icon','heart').'"></i></span>';
  122.                             $output .= get_the_post_thumbnail(null,'blog_carousel');
  123.                             $output .= '</a></div>';
  124.                         }
  125.                         $output .= '<h4>'.get_the_title().'</h4>';
  126.                         $output .= '<p>'.  word_trim(get_the_excerpt(), 15, '...').'</p>';
  127.                         $output .= '<p><a href="'.  get_permalink() .'" class="small button radius secondary"><i class="icon-angle-right"></i> '.__("READ MORE", 'kleo_framework').'</a></p>';
  128.                         $output .= '</li>';
  129.                     break;
  130.             }
  131.  
  132.         endwhile;
  133.         wp_reset_postdata();
  134.         $output .= '</ul></div><!--end carousel-stories-->'.
  135.                 '</div>';
  136.        
  137.         return $output;
  138.     }
  139.     add_shortcode( 'kleo_posts_carousel', 'kleo_posts_carousel' );
  140. }
Advertisement
Add Comment
Please, Sign In to add comment