我正在尝试使用ACF和CPT UI使bootstrap 5.0 carousel(带指示器)动态化。我意识到我需要在data-bs-slide-to
以及其他数字和箭头以及class="active"
也是动态的,但我不知道怎么做。现在,我可以同时显示所有幻灯片—一张放在另一张的上面。如果插入参数\'posts_per_page\' => 1
, 然后第一张幻灯片就可以看到了,但旋转木马不会旋转。
My code:
<!-- Carousel from bootstrap-->
<div id="carouselBootStrap" class="carousel slide" data-bs-ride="carousel">
<ol class="carousel-indicators">
<li data-bs-target="#carouselBootStrap" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1">1</li>
<li data-bs-target="#carouselBootStrap" data-bs-slide-to="1" aria-label="Slide 2">2</li>
<li data-bs-target="#carouselBootStrap" data-bs-slide-to="2" aria-label="Slide 3">3</li>
</ol>
<div class="carousel-inner">
<?php $loop = new WP_Query(array(\'post_type\' => \'slider_feature\', \'orderby\' => \'ID\', \'order\' => \'ASC\' )); ?>
<?php while ($loop->have_posts()): $loop->the_post(); ?>
<div class="carousel-item active dark-header-overlay">
<h2 class="centered font-sl-head"><?php the_field(\'slide_text\'); ?> <img class="img-hline" src="<?php the_field(\'small_slide_img\'); ?>" alt=""></h2>
<img class="d-block w-100 h-70" src="<?php the_field(\'img_slide\'); ?>" alt="">
</div>
<?php endwhile;
wp_reset_query(); ?>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselBootStrap" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselBootStrap" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>