Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save anthonyfajardo/05aabe66400ad28935a35991b537268e to your computer and use it in GitHub Desktop.
Save anthonyfajardo/05aabe66400ad28935a35991b537268e to your computer and use it in GitHub Desktop.
Bootstrap 4 Carousel on WordPress ACF Pro Gallery
<?php
/* FRONT-PAGE SLIDER WITH ACF GALLERY AND BOOTSTRAP 4 CAROUSEL */
$images = get_field('banner_images');
$count=0;
$count1=0;
if($images) : ?>
<div id="slider">
<div id="carousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<?php foreach( $images as $image ): ?>
<li data-target="#carousel" data-slide-to="<?php echo $count; ?>" <?php if($count==0) : ?>class="active"<?php endif; ?>></li>
<?php
$count++;
endforeach; ?>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<?php foreach( $images as $image ): ?>
<div class="carousel-item <?php if($count1==0) : echo ' active'; endif; ?>">
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
</div><!-- item -->
<?php $count1++; ?>
<?php endforeach; ?>
</div><!-- carousel inner -->
<?php /* CAROUSEL CONTROL PREVIOUS & NEXT */ ?>
<a class="carousel-control-prev" href="#carousel" 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="#carousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div><!-- #carousel -->
</div><!--#slider-->
<?php endif; ?>
@anthonyfajardo
Copy link
Author

I made a few modifications to the code from hgsinfotech.com's site:

The original code is from the link below.
http://www.hgsinfotech.com/acf-gallery-slider-bootstrap-carousel/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment