在滑块中显示10张图像

时间:2018-07-10 11:51:03

标签: php wordpress

enter image description here

V.init(frame:) is called indirectly but V doesn't override this designated initializer. Please override init(frame:) to fix this issue

我有上面的代码,它希望连续显示10张图像,我希望它在滑块中显示10张图像,但它不起作用 我尝试过bxslider它只能在滑块中添加一个图像

$query = new WP_Query( array( 'post_type' => 'testimonial' , 'posts_per_page' => 10,) );
    if ( $query->have_posts() ) : ?>
    <?php while ( $query->have_posts() ) : $query->the_post(); ?>   
    <div class="testimonial-image">
    <?php echo get_the_post_thumbnail();?>
    </div>
    <?php endwhile; wp_reset_postdata(); ?>
    <?php endif; ?>

enter image description here 请帮助我让所有图像都在滑块内工作,请看一下我的图像

2 个答案:

答案 0 :(得分:0)

如果您谈论this bxslider,我看到您必须具有一个带有bxslider类(或您在JS代码中定义的“ testimonials-carousel-content”)的主换行div,并且内部DIV包含每个图像。

因此,您的代码必须像这样:

<?php if ( $query->have_posts() ) : ?>
<div class="testimonials-carousel-content">
<?php while ( $query->have_posts() ) : $query->the_post(); ?> 
<div><?php echo get_the_post_thumbnail();?></div>
<?php endwhile; wp_reset_postdata(); ?>
</div>
<?php endif; ?> 

和JS代码(来自示例):

$(function(){
  $('.testimonials-carousel-content').bxSlider({
    mode: 'fade',
    captions: true,
    slideWidth: 600
  });
});

答案 1 :(得分:0)

Slick看起来像一个适合您想要实现的插件。您还可以尝试加载WordPress plugins的负载。