wordpress网站中的woocommerce类旋转木马

时间:2015-02-23 04:15:49

标签: wordpress plugins slider woocommerce categories

我想在我的wordpress主页上添加woocommerce产品类别轮播。为此我使用WpF Ultimate Carousel 插件支持自定义帖子类型,但不显示产品类别。这是代码

function wpf_ultimate_carousel_shortcode($atts){
extract( shortcode_atts( array(
    'post_type' => 'post', 
    'category' => '',   
    'count' => '-1', 
    'taxonomy' => 'category_name',  
    'name' => 'carousel',   
    'slides' => '4',    
    'scroll' => '1',    
    'autoplay' => 'false',  
    'speed' => '2000',  
    'title_color' => '#000000', 
    'title_bg_color' => '', 
    'link_color' => '#222222',
    'title' => 'More...'    
), $atts, 'wpf_carousel' ) );



global $post;
$args = array( 'posts_per_page' => $count, 'post_type' => $post_type, $taxonomy => $category);
$myposts = get_posts( $args );

$list = '

    <script type="text/javascript">

        jQuery(document).ready(function(){

            jQuery("#wpf_'.$name.'").slick({
              slidesToShow: '.$slides.',
              slidesToScroll: '.$scroll.',
              autoplay: '.$autoplay.',
              autoplaySpeed: '.$speed.',
            });

        });

    </script>

    <div class="wpf_carousel_container" style="width:80%;margin:0 auto;">

        <h2 style="color:'.$title_color.';background:'.$title_bg_color.';">'.$title.'</h2>
    <div id="wpf_'.$name.'">';


foreach( $myposts as $post ) : setup_postdata($post);

$post_thumbnail= get_the_post_thumbnail( $post->ID, 'wpf-carousel-image-big',array('alt' => get_the_title(),'title' => get_the_title())); 
$list .= '


    <div class="wpf_slides">
        '.$post_thumbnail.'
        <h2><a style="color:'.$link_color.'" href="'.get_permalink().'">'.ShortenText(get_the_title()).'</a></h2>
    </div>


';  

endforeach; 



  $list.= '</div></div>';
  wp_reset_query();
 return $list;
}
add_shortcode('wpf_carousel', 'wpf_ultimate_carousel_shortcode');


 // title shortner

 function ShortenText($text) { // Function name ShortenText
  $chars_limit = 30; // Character length
  $chars_text = strlen($text);
  $text = $text." ";
  $text = substr($text,0,$chars_limit);
  $text = substr($text,0,strrpos($text,' '));

  if ($chars_text > $chars_limit)
   { $text = $text.".."; } // Ellipsis
 return $text;
}
 add_shortcode('shortentitle', 'ShortenText'); 

页面中使用的短代码是[wpf_carousel name =“my-carousel-3”taxonomy =“product_cat”post_type =“product”title =“test”]  输出为output而不是产品;该类别是必需的。

请帮助我..提前致谢

0 个答案:

没有答案