一次显示一份推荐

时间:2018-07-10 09:45:09

标签: php wordpress

enter image description here

  <?php $query = new WP_Query( 
         array( 'post_type' => 'testimonial' ,
                'posts_per_page' => -1,
               ) );

    if ( $query->have_posts() ) : ?>
    <?php while ( $query->have_posts() ) : $query->the_post(); ?> 
    <div class="testimonials-name"><?php the_title();?></div>
    <div class="testimonials-carousel-content"><p><?php the_content() ;?></p></div>

    <?php endwhile; wp_reset_postdata(); ?>
    <!-- show pagination here -->
    <?php else : ?>

    <!-- show 404 error here -->
    <?php endif; ?>

我有此查询,但是它显示所有推荐书,我希望它一次显示一个推荐书,请帮忙

我无法执行此操作

2 个答案:

答案 0 :(得分:0)

如果您正在使用bxslider,则需要将bxslider定位到的类添加到html中。像这样:

<div class="testimonials-slider">
if ( $query->have_posts() ) : ?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?> 
<div class="testimonials-name"><?php the_title();?></div>
<div class="testimonials-carousel-content"><p><?php the_content() ;?></p></div>

<?php endwhile; wp_reset_postdata(); ?>
</div>


<!-- show pagination here -->
<?php else : ?>

<!-- show 404 error here -->
<?php endif; ?>

答案 1 :(得分:0)

您没有以正确的方式初始化bx滑块,请尝试以下代码

<div class="testimonials-slider bxslider">
<?php $query = new WP_Query( array( 'post_type' => 'testimonial' , 'posts_per_page' => -1,) );

         if ( $query->have_posts() ) : ?>
         <?php while ( $query->have_posts() ) : $query->the_post(); ?> 
         <div class="testimonials-name"><?php the_title();?></div>
         <div class="testimonials-carousel-content"><p><?php the_content() ;?></p></div>

        <?php endwhile; wp_reset_postdata(); ?>
        <!-- show pagination here -->
        <?php else : ?>

        <!-- show 404 error here -->
        <?php endif; ?>
</div>

<script type="text/javascript">
         $(document).ready(function () {           
             $('.testimonials-slider').bxSlider({
                 mode: 'vertical',
                 slideMargin: 3,
                 auto:true
             });             
         });
    </script>