/** * Create a slider with posts retrieved through get_posts * @param Object $atts * @param String $content * @return String */ function themify_shortcode_post_slider($atts, $content = null) { extract(shortcode_atts(array('visible' => '1', 'scroll' => '1', 'auto' => '0', 'pause_hover' => 'no', 'wrap' => 'yes', 'excerpt_length' => '20', 'speed' => 'normal', 'slider_nav' => 'yes', 'pager' => 'yes', 'limit' => '5', 'offset' => '0', 'category' => '', 'image' => 'yes', 'image_w' => '240px', 'image_h' => '180px', 'more_text' => __('More...', 'themify'), 'title' => 'yes', 'display' => 'none', 'post_meta' => 'no', 'post_date' => 'no', 'width' => '100%', 'height' => 'auto', 'class' => '', 'unlink_title' => 'no', 'unlink_image' => 'no', 'image_size' => 'medium', 'post_type' => 'post', 'taxonomy' => 'category', 'order' => 'DESC', 'orderby' => 'date', 'effect' => 'scroll'), $atts, 'themify_post_slider')); $postsliderstr = ''; global $post; $query_args = array('numberposts' => $limit, 'offset' => $offset, 'post_type' => $post_type, 'order' => $order, 'orderby' => $orderby, 'suppress_filters' => false, 'post__not_in' => !is_home() ? array(get_the_ID()) : array()); if ('' != $category) { $tax_query_terms = explode(',', $category); if (preg_match('#[a-z]#', $category)) { $query_args['tax_query'] = array(array('taxonomy' => $taxonomy, 'field' => 'slug', 'terms' => $tax_query_terms)); } else { $exclude = array_filter($tax_query_terms, 'themify_is_negative_number'); $query_args['tax_query'] = array('relation' => 'AND', array('taxonomy' => $taxonomy, 'field' => 'id', 'terms' => array_filter($tax_query_terms, 'themify_is_positive_number')), array('taxonomy' => $taxonomy, 'field' => 'id', 'terms' => array_map('themify_make_absolute_number', $exclude), 'operator' => 'NOT IN')); } } $posts = get_posts(apply_filters('themify_post_slider_shortcode_query_args', $query_args, $atts)); if ($posts) { switch ($speed) { case 'fast': $speed = '.5'; break; case 'normal': $speed = '1'; break; case 'slow': $speed = '4'; break; } $class .= ' effect-' . $effect; $js_data['slider_nav'] = $slider_nav == 'yes' ? 1 : 0; $js_data['pager'] = $pager == 'yes' ? 1 : 0; $js_data['wrapvar'] = $wrap == 'yes' ? 1 : 0; $js_data['play'] = intval($auto); $js_data['pause_hover'] = $pause_hover == 'yes' ? 1 : 0; $js_data['speed'] = $speed; $js_data['scroll'] = $scroll; $js_data['effect'] = $effect; $js_data['visible'] = intval($visible); $js_data['numsldr'] = rand(0, 1011) . uniqid(); $postsliderstr = '<!-- shortcode post_slider --> <div id="slider-' . esc_attr($js_data['numsldr']) . '" style="width: ' . esc_attr($width) . '; height: ' . esc_attr($height) . ';" class="shortcode clearfix post-slider ' . $class . '"> <ul class="slides" data-slider="' . esc_attr(json_encode($js_data)) . '">'; unset($js_data); foreach ($posts as $post) { setup_postdata($post); global $more; $more = 0; $post_class = ''; foreach (get_post_class() as $postclass) { $post_class .= " " . $postclass; } //get_post_class() as $postclass $postsliderstr .= '<li><div class="slide-wrap ' . esc_attr($post_class) . '">'; if ('yes' == $image) { $video_url = themify_get('video_url'); if ('' != $video_url) { $postsliderstr .= '<div class="post-video">'; global $wp_embed; $postsliderstr .= $wp_embed->run_shortcode('[embed]' . $video_url . '[/embed]'); $postsliderstr .= '</div>'; } else { if ('no' == $unlink_image) { $postsliderstr .= themify_get_image(array('image_size=' => $image_size, 'ignore' => true, 'w' => $image_w, 'h' => $image_h, 'alt' => get_the_title(), 'before' => '<p class="post-image"><a href="' . themify_get_featured_image_link() . '">', 'after' => '</a></p>')); } else { $postsliderstr .= themify_get_image(array('image_size' => $image_size, 'ignore' => true, 'w' => $image_w, 'h' => $image_h, 'alt' => get_the_title(), 'before' => '<p class="post-image">', 'after' => '</p>')); } } } //'yes' == $image if ('yes' == $title) { if ('no' == $unlink_title) { $postsliderstr .= '<h3 class="post-title"><a href="' . themify_get_featured_image_link() . '">' . get_the_title() . '</a></h3>'; } else { $postsliderstr .= '<h3 class="post-title">' . get_the_title() . '</h3>'; } } //$title == "yes" if ($post_date == "yes") { $postsliderstr .= '<p class="post-date">' . get_the_date() . '</p>'; } //$post_date == "yes" if ('yes' == $post_meta) { $postsliderstr .= '<p class="post-meta"> <span class="post-author">' . get_the_author() . '</span> <span class="post-category">' . get_the_category_list(', ') . '</span>'; if (comments_open()) { ob_start(); comments_popup_link('0', '1', '%', 'comments-link', ''); $write_comments = ob_get_contents(); ob_clean(); } else { $write_comments = ''; } $postsliderstr .= '<span class="post-comment">' . $write_comments . '</span>'; if (has_tag()) { $postsliderstr .= '<span class="post-tag">' . get_the_tag_list('', ', ') . '</span>'; } $postsliderstr .= '</p>'; } //$post_meta == "yes" if ('content' == $display) { $postsliderstr .= '<div class="post-content">' . wp_kses_post(themify_get_content($more_text)) . '</div></div></li>'; } //$display == "content" if ('excerpt' == $display) { $postsliderstr .= '<div class="post-content">' . wp_kses_post(themify_excerpt($excerpt_length)) . '</div></div></li>'; } //$display == "excerpt" } $postsliderstr .= '</ul>'; $postsliderstr .= '</div> <!-- /shortcode post_slider -->'; wp_reset_postdata(); } //$posts return $postsliderstr; }
/** * Create a slider with posts retrieved through get_posts * @param Object $atts * @param String $content * @return String */ function themify_shortcode_post_slider($atts, $content = null) { wp_enqueue_script('themify-carousel-js'); extract(shortcode_atts(array('visible' => '1', 'scroll' => '1', 'auto' => '0', 'wrap' => 'yes', 'excerpt_length' => '20', 'speed' => 'normal', 'slider_nav' => 'yes', 'pager' => 'yes', 'limit' => '5', 'category' => '', 'image' => 'yes', 'image_w' => '240px', 'image_h' => '180px', 'more_text' => __('More...', 'themify'), 'title' => 'yes', 'display' => 'none', 'post_meta' => 'no', 'post_date' => 'no', 'width' => '', 'height' => '', 'class' => '', 'unlink_title' => 'no', 'unlink_image' => 'no', 'image_size' => 'thumbnail', 'post_type' => 'post', 'order' => 'DESC', 'orderby' => 'date', 'effect' => 'scroll'), $atts)); $wrapvar = 'false'; if ('yes' == $wrap) { $wrapvar = 'true'; } if ('0' == $auto) { $play = 'false'; } else { $play = 'true'; } switch ($speed) { case 'fast': $speed = '.5'; break; case 'normal': $speed = '1'; break; case 'slow': $speed = '4'; break; } $numsldr = rand(0, 10000); $postsliderstr = ''; global $post; $query_args = array('numberposts' => $limit, 'post_type' => $post_type, 'order' => $order, 'orderby' => $orderby, 'suppress_filters' => false, 'post__not_in' => array(get_the_ID())); if ('' != $category) { $tax_query_terms = explode(',', $category); if (preg_match('#[a-z]#', $category)) { $query_args['tax_query'] = array(array('taxonomy' => 'category', 'field' => 'slug', 'terms' => $tax_query_terms)); } else { $query_args['tax_query'] = array(array('taxonomy' => 'category', 'field' => 'id', 'terms' => $tax_query_terms)); } } $posts = get_posts($query_args); $class .= ' effect-' . $effect; if ($posts) { $postsliderstr = '<!-- shortcode post_slider --> <div id="post-slider-' . $numsldr . '" style="width: ' . $width . '; height: ' . $height . ';" class="shortcode clearfix post-slider ' . $class . '"> <ul class="slides">'; foreach ($posts as $post) { setup_postdata($post); global $more; $more = 0; $post_class = ''; if (themify_get('external_link') != '') { $thislink = themify_get('external_link'); } else { $thislink = get_permalink(); } foreach (get_post_class() as $postclass) { $post_class .= " " . $postclass; } //get_post_class() as $postclass $postsliderstr .= '<li><div class="slide-wrap ' . $post_class . '">'; if ('yes' == $image) { $video_url = themify_get('video_url'); if ('' != $video_url) { $postsliderstr .= '<div class="post-video">'; global $wp_embed; $postsliderstr .= $wp_embed->run_shortcode('[embed]' . $video_url . '[/embed]'); $postsliderstr .= '</div>'; } else { if ('no' == $unlink_image) { $postsliderstr .= themify_get_image('image_size=' . $image_size . '&ignore=true&w=' . $image_w . '&h=' . $image_h . '&alt=' . get_the_title() . '&before=<p class="post-image"><a href="' . $thislink . '">&after=</a></p>'); } else { $postsliderstr .= themify_get_image('image_size=' . $image_size . '&ignore=true&w=' . $image_w . '&h=' . $image_h . '&alt=' . get_the_title() . '&before=<p class="post-image">&after=</p>'); } } } //'yes' == $image if ('yes' == $title) { if ('no' == $unlink_title) { $postsliderstr .= '<h3 class="post-title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h3>'; } else { $postsliderstr .= '<h3 class="post-title">' . get_the_title() . '</h3>'; } } //$title == "yes" if ($post_date == "yes") { $postsliderstr .= '<p class="post-date">' . get_the_date() . '</p>'; } //$post_date == "yes" if ('yes' == $post_meta) { $postsliderstr .= '<p class="post-meta"> <span class="post-author">' . get_the_author() . '</span> <span class="post-category">' . get_the_category_list(', ') . '</span>'; $num_comments = get_comments_number(); if (comments_open()) { ob_start(); comments_popup_link('0', '1', '%', 'comments-link', ''); $write_comments = ob_get_contents(); ob_clean(); } else { $write_comments = ''; } $postsliderstr .= '<span class="post-comment">' . $write_comments . '</span>'; if (has_tag()) { $postsliderstr .= '<span class="post-tag">' . get_the_tag_list('', ', ') . '</span>'; } $postsliderstr .= '</p>'; } //$post_meta == "yes" if ('content' == $display) { $postsliderstr .= '<div class="post-content">' . themify_get_content($more_text) . '</div></div></li> '; } //$display == "content" if ('excerpt' == $display) { $postsliderstr .= '<div class="post-content">' . themify_excerpt($excerpt_length) . '</div></div></li> '; } //$display == "excerpt" } $postsliderstr .= '</ul>'; if ('yes' == $slider_nav) { $nextbutton = '<div>»</div>'; $prevbutton = '<div>«</div>'; } else { $nextbutton = "null"; $prevbutton = "null"; } //$slider_nav == "yes" $postsliderstr .= '</div><script type="text/javascript"> jQuery(window).load(function() { jQuery("#post-slider-' . $numsldr . ' .slides").carouFredSel({ responsive: true,'; if ('yes' == $slider_nav) { $postsliderstr .= ' prev: "#post-slider-' . $numsldr . ' .carousel-prev", next: "#post-slider-' . $numsldr . ' .carousel-next",'; } if ('yes' == $pager) { $postsliderstr .= ' pagination: "#post-slider-' . $numsldr . ' .carousel-pager",'; } $postsliderstr .= ' circular: ' . $wrapvar . ', infinite: ' . $wrapvar . ', auto: { play : ' . $play . ', pauseDuration: ' . $auto . '*1000, duration: ' . $speed . '*1000 }, scroll: { items: ' . $scroll . ', duration: ' . $speed . '*1000, wipe: true, fx: "' . $effect . '" }, items: { visible: { min: 1, max: ' . $visible . ' }, width: 120 }, onCreate : function (){ jQuery(".post-slider").css( { "height": "auto", "visibility" : "visible" }); } }); }); </script> <!-- /shortcode post_slider -->'; wp_reset_postdata(); } //$posts return $postsliderstr; }
/** * Create a slider with posts retrieved through get_posts * @param Object $atts * @param String $content * @return String */ function themify_shortcode_post_slider($atts, $content = null) { wp_enqueue_script('themify-carousel-js'); extract(shortcode_atts(array('visible' => '1', 'scroll' => '1', 'auto' => '0', 'pause_hover' => 'no', 'wrap' => 'yes', 'excerpt_length' => '20', 'speed' => 'normal', 'slider_nav' => 'yes', 'pager' => 'yes', 'limit' => '5', 'offset' => '0', 'category' => '', 'image' => 'yes', 'image_w' => '240px', 'image_h' => '180px', 'more_text' => __('More...', 'themify'), 'title' => 'yes', 'display' => 'none', 'post_meta' => 'no', 'post_date' => 'no', 'width' => '', 'height' => '', 'class' => '', 'unlink_title' => 'no', 'unlink_image' => 'no', 'image_size' => 'medium', 'post_type' => 'post', 'taxonomy' => 'category', 'order' => 'DESC', 'orderby' => 'date', 'effect' => 'scroll'), $atts, 'themify_post_slider')); $wrapvar = 'false'; if ('yes' == $wrap) { $wrapvar = 'true'; } if ('0' == $auto) { $play = 'false'; } else { $play = 'true'; } switch ($speed) { case 'fast': $speed = '.5'; break; case 'normal': $speed = '1'; break; case 'slow': $speed = '4'; break; } $pause_hover = $pause_hover == 'yes' ? 'true' : 'false'; $numsldr = rand(0, 10000); $postsliderstr = ''; global $post; $query_args = array('numberposts' => $limit, 'offset' => $offset, 'post_type' => $post_type, 'order' => $order, 'orderby' => $orderby, 'suppress_filters' => false, 'post__not_in' => array(get_the_ID())); if ('' != $category) { $tax_query_terms = explode(',', $category); if (preg_match('#[a-z]#', $category)) { $query_args['tax_query'] = array(array('taxonomy' => $taxonomy, 'field' => 'slug', 'terms' => $tax_query_terms)); } else { $exclude = array_filter($tax_query_terms, 'themify_is_negative_number'); $query_args['tax_query'] = array('relation' => 'AND', array('taxonomy' => $taxonomy, 'field' => 'id', 'terms' => array_filter($tax_query_terms, 'themify_is_positive_number')), array('taxonomy' => $taxonomy, 'field' => 'id', 'terms' => array_map('themify_make_absolute_number', $exclude), 'operator' => 'NOT IN')); } } $posts = get_posts($query_args); $class .= ' effect-' . $effect; if ($posts) { $postsliderstr = '<!-- shortcode post_slider --> <div id="post-slider-' . esc_attr($numsldr) . '" style="width: ' . esc_attr($width) . '; height: ' . esc_attr($height) . ';" class="shortcode clearfix post-slider ' . $class . '"> <ul class="slides">'; foreach ($posts as $post) { setup_postdata($post); global $more; $more = 0; $post_class = ''; foreach (get_post_class() as $postclass) { $post_class .= " " . $postclass; } //get_post_class() as $postclass $postsliderstr .= '<li><div class="slide-wrap ' . esc_attr($post_class) . '">'; if ('yes' == $image) { $video_url = themify_get('video_url'); if ('' != $video_url) { $postsliderstr .= '<div class="post-video">'; global $wp_embed; $postsliderstr .= $wp_embed->run_shortcode('[embed]' . $video_url . '[/embed]'); $postsliderstr .= '</div>'; } else { if ('no' == $unlink_image) { $postsliderstr .= themify_get_image(array('image_size=' => $image_size, 'ignore' => true, 'w' => $image_w, 'h' => $image_h, 'alt' => get_the_title(), 'before' => '<p class="post-image"><a href="' . themify_get_featured_image_link() . '">', 'after' => '</a></p>')); } else { $postsliderstr .= themify_get_image(array('image_size' => $image_size, 'ignore' => true, 'w' => $image_w, 'h' => $image_h, 'alt' => get_the_title(), 'before' => '<p class="post-image">', 'after' => '</p>')); } } } //'yes' == $image if ('yes' == $title) { if ('no' == $unlink_title) { $postsliderstr .= '<h3 class="post-title"><a href="' . themify_get_featured_image_link() . '">' . get_the_title() . '</a></h3>'; } else { $postsliderstr .= '<h3 class="post-title">' . get_the_title() . '</h3>'; } } //$title == "yes" if ($post_date == "yes") { $postsliderstr .= '<p class="post-date">' . get_the_date() . '</p>'; } //$post_date == "yes" if ('yes' == $post_meta) { $postsliderstr .= '<p class="post-meta"> <span class="post-author">' . get_the_author() . '</span> <span class="post-category">' . get_the_category_list(', ') . '</span>'; if (comments_open()) { ob_start(); comments_popup_link('0', '1', '%', 'comments-link', ''); $write_comments = ob_get_contents(); ob_clean(); } else { $write_comments = ''; } $postsliderstr .= '<span class="post-comment">' . $write_comments . '</span>'; if (has_tag()) { $postsliderstr .= '<span class="post-tag">' . get_the_tag_list('', ', ') . '</span>'; } $postsliderstr .= '</p>'; } //$post_meta == "yes" if ('content' == $display) { $postsliderstr .= '<div class="post-content">' . wp_kses_post(themify_get_content($more_text)) . '</div></div></li> '; } //$display == "content" if ('excerpt' == $display) { $postsliderstr .= '<div class="post-content">' . wp_kses_post(themify_excerpt($excerpt_length)) . '</div></div></li> '; } //$display == "excerpt" } $postsliderstr .= '</ul>'; $postsliderstr .= '</div> <script type="text/javascript"> (function($){ $(window).load(function() { var $slider_slides = $("#post-slider-' . $numsldr . ' .slides"); $("#post-slider-' . $numsldr . ' .slides").carouFredSel({ responsive: true,'; if ('yes' == $slider_nav) { $postsliderstr .= ' prev: "#post-slider-' . $numsldr . ' .carousel-prev", next: "#post-slider-' . $numsldr . ' .carousel-next",'; } if ('yes' == $pager) { $postsliderstr .= ' pagination: "#post-slider-' . $numsldr . ' .carousel-pager",'; } $postsliderstr .= ' circular: ' . $wrapvar . ', infinite: ' . $wrapvar . ', auto: { play : ' . $play . ', timeoutDuration: ' . $auto . '*1000, duration: ' . $speed . '*1000, pauseOnHover: ' . $pause_hover . ' }, swipe: true, scroll: { items: ' . $scroll . ', duration: ' . $speed . '*1000, fx: "' . $effect . '" }, items: { visible: { min: 1, max: ' . $visible . ' }, width: 120 }, onCreate : function (){ jQuery(".post-slider").css( { "height": "auto", "visibility" : "visible" }); } }); var tscpsDidResize = false; $(window).on("resize", function() { tscpsDidResize = true; }); setInterval(function() { if ( tscpsDidResize ) { tscpsDidResize = false; $(".slides").each(function(){ var heights = [], newHeight, $self = $(this); $self.find("li").each( function() { heights.push( $(this).outerHeight() ); }); newHeight = Math.max.apply( Math, heights ); $self.outerHeight( newHeight ); $(".caroufredsel_wrapper").outerHeight( newHeight ); }); } }, 500); }); })(jQuery); </script> <!-- /shortcode post_slider -->'; wp_reset_postdata(); } //$posts return $postsliderstr; }
/** * Create a slider with posts retrieved through get_posts * @param Object $atts * @param String $content * @return String */ function themify_shortcode_post_slider($atts, $content = null) { extract(shortcode_atts(array('visible' => '1', 'scroll' => '1', 'auto' => '0', 'wrap' => 'no', 'excerpt_length' => '20', 'speed' => 'normal', 'slider_nav' => 'yes', 'limit' => '5', 'category' => '', 'image' => 'yes', 'image_w' => '240px', 'image_h' => '180px', 'more_text' => 'More...', 'title' => 'yes', 'display' => 'none', 'post_meta' => 'no', 'post_date' => 'no', 'width' => '', 'height' => '', 'class' => '', 'unlink_title' => 'no', 'unlink_image' => 'no'), $atts)); if ($wrap == "yes") { $wrapvar = "circular"; } if ($wrap == "no") { $wrapvar = "null"; } $numsldr = rand(0, 10000); global $wpdb, $post, $table_prefix; if ($category == 0) { $posts = get_posts(array('numberposts' => $limit)); } else { $arraycat = array($category); $listcat = $category; $arraycat = explode(',', $listcat); $posts = get_posts('category=' . $listcat . '&numberposts=' . $show); } if ($posts) { $postsliderstr = '<!-- shortcode post_slider --> <div id="post-slider-' . $numsldr . '" style="width: ' . $width . '; height: ' . $height . ';" class="shortcode clearfix post-slider ' . $class . '"> <ul class="slides">'; foreach ($posts as $post) { setup_postdata($post); global $more; $more = 0; $post_class = ""; if (themify_get('external_link') != '') { $thislink = themify_get('external_link'); } else { $thislink = get_permalink(); } foreach (get_post_class() as $postclass) { $post_class .= " " . $postclass; } //get_post_class() as $postclass $postsliderstr .= '<li><div class="slide-wrap ' . $post_class . '">'; if ($image == "yes") { if ('no' == $unlink_image) { $postsliderstr .= themify_get_image('ignore=true&w=' . $image_w . '&h=' . $image_h . '&alt=' . get_the_title() . '&before=<p class="post-image"><a href="' . $thislink . '">&after=</a></p>'); } else { $postsliderstr .= themify_get_image('ignore=true&w=' . $image_w . '&h=' . $image_h . '&alt=' . get_the_title() . '&before=<p class="post-image">&after=</p>'); } } //$image == "yes" if ($title == "yes") { if ('no' == $unlink_title) { $postsliderstr .= '<h3 class="post-title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h3>'; } else { $postsliderstr .= '<h3 class="post-title">' . get_the_title() . '</h3>'; } } //$title == "yes" if ($post_date == "yes") { $postsliderstr .= '<p class="post-date">' . get_the_date() . '</p>'; } //$post_date == "yes" if ($post_meta == "yes") { $postsliderstr .= '<p class="post-meta"> <span class="post-author">' . get_the_author() . '</span> <span class="post-category">' . get_the_category_list(', ') . '</span>'; $num_comments = get_comments_number(); if (comments_open()) { ob_start(); comments_popup_link('0', '1', '%', 'comments-link', ''); $write_comments = ob_get_contents(); ob_clean(); } else { $write_comments = __(''); } $postsliderstr .= '<span class="post-comment">' . $write_comments . '</span>'; if (has_tag()) { $postsliderstr .= '<span class="post-tag">' . get_the_tag_list('', ', ') . '</span>'; } $postsliderstr .= '</p>'; } //$post_meta == "yes" if ($display == "content") { $postsliderstr .= '<div class="post-content">' . themify_get_content($more_text) . '</div></div></li> '; } //$display == "content" if ($display == "excerpt") { $postsliderstr .= '<div class="post-content">' . themify_excerpt($excerpt_length) . '</div></div></li> '; } //$display == "excerpt" } $postsliderstr .= '</ul>'; if ($slider_nav == "yes") { $nextbutton = "<div>»</div>"; $prevbutton = "<div>«</div>"; } else { $nextbutton = "null"; $prevbutton = "null"; } //$slider_nav == "yes" $postsliderstr .= '</div><script type="text/javascript"> function carousel_callback_' . $numsldr . '(carousel) { // Disable autoscrolling if the user clicks the prev or next button. carousel.buttonNext.bind("click", function() { carousel.startAuto(0); }); carousel.buttonPrev.bind("click", function() { carousel.startAuto(0); }); // Pause autoscrolling if the user moves with the cursor over the clip. carousel.clip.hover(function() { carousel.stopAuto(); }, function() { carousel.startAuto(); }); } jQuery(document).ready(function($) { $("#post-slider-' . $numsldr . '").jcarousel({ wrap: "' . $wrapvar . '", auto: ' . $auto . ', visible: ' . $visible . ', scroll: ' . $scroll . ', animation: "' . $speed . '", buttonNextHTML: "' . $nextbutton . '", buttonPrevHTML: "' . $prevbutton . '", initCallback: carousel_callback_' . $numsldr . ' }); }); </script> <!-- /shortcode post_slider -->'; wp_reset_postdata(); } //$posts return $postsliderstr; }