Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1293383
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 3 years ago.
Improve this questionI am trying to make bootstrap 5.0 carousel (with indicators) dynamic using ACF and CPT UI. I realized that I need to display the number in data-bs-slide-to
dynamically, as well as other numbers and arrows and the class="active"
also dynamically, but I don't know how. I now have all the slides displayed at once - one on top of the other. If you insert the parameter 'posts_per_page' => 1
, then the first slide is visible, as it should be, but the carousel does not spin.
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>
Closed. This question is off-topic. It is not currently accepting answers.
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 3 years ago.
Improve this questionI am trying to make bootstrap 5.0 carousel (with indicators) dynamic using ACF and CPT UI. I realized that I need to display the number in data-bs-slide-to
dynamically, as well as other numbers and arrows and the class="active"
also dynamically, but I don't know how. I now have all the slides displayed at once - one on top of the other. If you insert the parameter 'posts_per_page' => 1
, then the first slide is visible, as it should be, but the carousel does not spin.
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>
Share
Improve this question
asked May 4, 2021 at 12:44
Brgerg30879Brgerg30879
74 bronze badges
1 Answer
Reset to default 0I found a solution:
Make loop everywhere and increment i
variable
<!-- Carousel from bootstrap-->
<div id="carouselBootStrap" class="carousel slide" data-bs-ride="carousel">
<?php $loop = new WP_Query(array('post_type' => 'slider_feature', 'orderby' => 'ID', 'order' => 'ASC' )); ?>
<?php if( $loop->have_posts()): $i = 0; ?>
<ol class="carousel-indicators">
<?php while ($loop->have_posts()): $loop->the_post(); ?>
<li data-bs-target="#carouselBootStrap" data-bs-slide-to="<?php echo $i; ?>" class="<?php if($i == 0) echo 'active'; ?>" aria-current="true" aria-label="Slide 1">
<!-- here I have number links -->
<?php echo $i+1; ?></li>
<?php $i++; endwhile; ?>
</ol>
<?php endif; ?>
<div class="carousel-inner">
<?php if( $loop->have_posts()): $i = 0; ?>
<?php while ($loop->have_posts()): $loop->the_post(); ?>
<div class="carousel-item dark-header-overlay <?php if($i == 0) echo 'active'; ?>">
<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 $i++; endwhile; ?>
<?php wp_reset_query(); ?>
<?php endif; ?>
</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>
本文标签: custom post typesMake bootstrap 50 carousel dynamic using ACF and CPT UI
版权声明:本文标题:custom post types - Make bootstrap 5.0 carousel dynamic using ACF and CPT UI 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741575106a2386236.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论