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 5 years ago.
Improve this questionI've been working on an ACF Gallery that uses the bootstrap carousel style.
I've got it to work but it seems to create an extra loop instead of closing it after the last image.
This is the code I have so far
<?php
$images = get_field('slider_portfolio');
$divider = 2;
if( $images ): ?>
<div id="mini-carousel2" class="carousel slide" data-ride="carousel">
<div class="carousel-inner" style="max-height: 250px;min-height: 250px">
<div class="carousel-item active">
<div class="row">
<?php
$total = count( $images );
$counter = 0;
foreach( $images as $image ):
$counter++; ?>
<div class="col-md-6 col-sm-12 col-xs-12">
<a href="<?php echo $image['sizes']['large']; ?>" class="fancybox img-<?php echo $counter; ?>" rel="mini" data-toggle="lightbox" data-gallery="portfolio-gallery">
<img class="img-fluid" src="<?php echo $image['sizes']['large']; ?>" alt="<?php echo $image['title']; ?>" />
</a>
</div>
<?php $current_position = $images->$image + 1;
if (/* $image < $image->$total && */ $counter % $divider == 0) : ?>
</div>
</div>
<div class="carousel-item">
<div class="row">
<?php endif; ?>
<?php endforeach; ?>
</div>
</div>
</div>
<!-- Controls -->
<a class="carousel-control-prev" href="#mini-carousel2" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span></a>
<a class="carousel-control-next" href="#mini-carousel2" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span></a></div>
<?php endif; ?>
Any help and advice would be appreciated.
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 5 years ago.
Improve this questionI've been working on an ACF Gallery that uses the bootstrap carousel style.
I've got it to work but it seems to create an extra loop instead of closing it after the last image.
This is the code I have so far
<?php
$images = get_field('slider_portfolio');
$divider = 2;
if( $images ): ?>
<div id="mini-carousel2" class="carousel slide" data-ride="carousel">
<div class="carousel-inner" style="max-height: 250px;min-height: 250px">
<div class="carousel-item active">
<div class="row">
<?php
$total = count( $images );
$counter = 0;
foreach( $images as $image ):
$counter++; ?>
<div class="col-md-6 col-sm-12 col-xs-12">
<a href="<?php echo $image['sizes']['large']; ?>" class="fancybox img-<?php echo $counter; ?>" rel="mini" data-toggle="lightbox" data-gallery="portfolio-gallery">
<img class="img-fluid" src="<?php echo $image['sizes']['large']; ?>" alt="<?php echo $image['title']; ?>" />
</a>
</div>
<?php $current_position = $images->$image + 1;
if (/* $image < $image->$total && */ $counter % $divider == 0) : ?>
</div>
</div>
<div class="carousel-item">
<div class="row">
<?php endif; ?>
<?php endforeach; ?>
</div>
</div>
</div>
<!-- Controls -->
<a class="carousel-control-prev" href="#mini-carousel2" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span></a>
<a class="carousel-control-next" href="#mini-carousel2" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span></a></div>
<?php endif; ?>
Any help and advice would be appreciated.
Share Improve this question edited May 23, 2019 at 8:22 Matthew asked May 23, 2019 at 7:56 MatthewMatthew 136 bronze badges1 Answer
Reset to default 1change the condition like this,
if ( ($counter % $divider == 0) && $total > $counter) : ?>