Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ( ! function_exists( 'kleo_posts_carousel' ) ) {
- function kleo_posts_carousel( $atts, $content = null ) {
- extract( shortcode_atts( array(
- 'cat' => 'all',
- 'limit' => 9,
- 'post_types' => 'post',
- 'post_formats' => 'image,gallery,video',
- 'class' => ''
- ), $atts));
- $output = '<div class="kleo-carousel '.$class.'">'.
- '<p>
- <span class="right hide-for-small">
- <a href="#" class="story-prev"><i class="icon-circle-arrow-left icon-large"></i></a>
- <a href="#" class="story-next"><i class="icon-circle-arrow-right icon-large"></i></a>
- </span>
- </p>
- <div class="carousel-stories responsive">
- <ul class="feature-stories">';
- $args = array();
- if ( (int) $cat != 0 ) {
- $args['cat'] = $cat;
- }
- if ( (int) $limit != 0 ) {
- $args['posts_per_page'] = $limit;
- }
- $args['post_type'] = explode(',', $post_types);
- $formats = explode( ',', $post_formats );
- if ( is_array( $formats ) && ! in_array( 'all', $formats ) ) {
- foreach( $formats as $format ) {
- $terms_query[] = 'post-format-' . $format;
- }
- $args['tax_query'] = array(
- array(
- 'taxonomy' => 'post_format',
- 'field' => 'slug',
- 'terms' => $terms_query
- )
- );
- }
- $latestPosts = new WP_Query( apply_filters( 'kleo_posts_carousel_args', $args ) );
- while ( $latestPosts->have_posts() ) : $latestPosts->the_post();
- switch (get_post_format()) {
- case 'video':
- $video = get_cfield('embed');
- if (!empty($video))
- {
- $output .= '<li>';
- $output .= wp_oembed_get($video);
- $output .= '<h4>'.get_the_title().'</h4>';
- $output .= '<p>'. word_trim(get_the_excerpt(), 15, '...').'</p>';
- $output .= '<p><a href="'. get_permalink() .'" class="small button radius secondary"><i class="icon-angle-right"></i> '.__("READ MORE", 'kleo_framework').'</a></p>';
- $output .= '</li>';
- }
- break;
- case 'gallery':
- $slides = get_cfield( 'slider' );
- if ( ! empty( $slides ) )
- {
- $output .= '<li>';
- $output .= '<div class="blog-slider">';
- foreach($slides as $slide)
- {
- if (get_attachment_id_from_url($slide))
- {
- $thumb_array = image_downsize( get_attachment_id_from_url($slide), 'blog_carousel' );
- $thumb_path = $thumb_array[0];
- }
- else
- {
- $thumb_path = $slide;
- }
- $output .= '<div data-thumb="'.$slide.'">';
- $output .= '<img src="'.$thumb_path.'" alt="">';
- $output .= '</div>';
- }
- $output .= '</div><!--end blog-slider-->';
- $output .= '<h4>'.get_the_title().'</h4>';
- $output .= '<p>'. word_trim(get_the_excerpt(), 15, '...').'</p>';
- $output .= '<p><a href="'. get_permalink() .'" class="small button radius secondary"><i class="icon-angle-right"></i> '.__("READ MORE", 'kleo_framework').'</a></p>';
- $output .= '</li>';
- }
- break;
- case 'image':
- if (get_post_thumbnail_id())
- {
- $output .= '<li>';
- $output .= '<div class=""><a class="imagelink" href="'. get_permalink().'">';
- $output .= '<span class="read"><i class="icon-'.apply_filters('kleo_img_rounded_icon','heart').'"></i></span>';
- $output .= get_the_post_thumbnail(null,'blog_carousel');
- $output .= '</a></div>';
- $output .= '<h4>'.get_the_title().'</h4>';
- $output .= '<p>'. word_trim(get_the_excerpt(), 15, '...').'</p>';
- $output .= '<p><a href="'. get_permalink() .'" class="small button radius secondary"><i class="icon-angle-right"></i> '.__("READ MORE", 'kleo_framework').'</a></p>';
- $output .= '</li>';
- }
- break;
- default:
- $output .= '<li>';
- if (get_post_thumbnail_id())
- {
- $output .= '<div class=""><a class="imagelink" href="'. get_permalink().'">';
- $output .= '<span class="read"><i class="icon-'.apply_filters('kleo_img_rounded_icon','heart').'"></i></span>';
- $output .= get_the_post_thumbnail(null,'blog_carousel');
- $output .= '</a></div>';
- }
- $output .= '<h4>'.get_the_title().'</h4>';
- $output .= '<p>'. word_trim(get_the_excerpt(), 15, '...').'</p>';
- $output .= '<p><a href="'. get_permalink() .'" class="small button radius secondary"><i class="icon-angle-right"></i> '.__("READ MORE", 'kleo_framework').'</a></p>';
- $output .= '</li>';
- break;
- }
- endwhile;
- wp_reset_postdata();
- $output .= '</ul></div><!--end carousel-stories-->'.
- '</div>';
- return $output;
- }
- add_shortcode( 'kleo_posts_carousel', 'kleo_posts_carousel' );
- }
Advertisement
Add Comment
Please, Sign In to add comment