Answer the question
In order to leave comments, you need to log in
Why is the carousel skipping the last item in the loop and how to fix it?
Hello! There is a implemented functionality, tied to a hybrid of carousels and tabs - fidl I
transferred it to wordpress and set the elements through the custom fields plugin . Everything would be fine, but now everything works (the carousel spins) only until the penultimate element and then returns to the first one. How to correct this moment?
<div id="myCarousel" class="carousel slide" data-ride="carousel" data-interval="">
<?php $test = new WP_Query([
'post_type' => 'gates',
'post_status' => 'publish',
'posts_per_page'=> -1,
'order' => 'ASC'
]); ?>
<?php $i=0; ?>
<!-- Indicators -->
<ol class="carousel-indicators">
<?php while($test->have_posts()): ?>
<?php $test->the_post(); ?>
<li data-target="#myCarousel" data-slide-to="<?php echo $i; ?>"<?php if($i==0) : echo ' class="active"'; endif; ?>>
<a data-toggle="pill" class="js-link js-link-<?php echo $i; ?>" href="#<?php echo ++$i; ?>"><?php the_post_thumbnail('full'); ?></a>
</li>
<?php endwhile ?>
<?php wp_reset_query() ?>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<?php $i = 0;
while($test->have_posts()): ?>
<?php $test->the_post(); ?>
<?php
$gallery = get_post_meta(get_the_ID(), 'gallery_types', true);
if($gallery):
$images = get_field('gallery_types');
if( $images ): ?>
<div class="item <?php if($i==0) : echo "active"; endif; ?>">
<?php foreach( $images as $image ): ?>
<img src="<?php echo $image['sizes']['large']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endforeach; ?>
</div>
<?php $i++; ?>
<?php endif; endif; ?>
<?php endwhile ?>
<?php wp_reset_query() ?>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev"></a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next"></a>
</div>
</div>
Answer the question
In order to leave comments, you need to log in
At first glance, it seems that in the .carousel-indicators block, controls are displayed simply by the presence of all gates posts, and in the output block of .item blocks there is a condition depending on the presence of $gallery and $images in it. Do you definitely have galleries in all your posts with at least one image?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question