Ashley Cameron Design

Ashley Cameron Design

Shop the Creative Design Market

Good morning

Bootstrap Carousel with Multiple Images using ACF Gallery & Fancybox

This post was last updated: Oct 8, 2022
SnippetsWordPress

About a 1 minute read

"Design is not just what it looks like and feels like. Design is how it works."

Steve Jobs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<section class="col-xs-12 col-sm-5 col-md-7">
    <h2>Mini Gallery</h2>
      <?php
        $images = get_field('gallery');
        $divider = 8; // # of items/thumbnails to show before closing the element and opening another
       
        if( $images ): ?>
       
          <div id="mini-carousel" class="carousel slide" data-ride="carousel">           
            <ul class="carousel-inner">
                <li class="item active">
                <?php
                    $total = count( $images );
                    $counter = 0;
                    foreach( $images as $image ):
                        $counter++; ?>
                   
                    <a href="<?php echo $image['sizes']['large']; ?>" class="fancybox img-<?php echo $counter; ?>" rel="mini">
                        <img class="img-responsive" src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['title']; ?>" />
                    </a>
                    <?php $current_position = $images->$image + 1; // current_post starts at 0
                        //if position is equal to the divider and not the last result close the currently open div and start another
                        if (/* $image < $image->$total && */ $counter % $divider == 0) : ?>
                            </li><li class="item">                         
                    <?php endif; ?>
                <?php endforeach; ?>
                </li>
            </ul>
           
            <!-- Controls -->
            <a class="left carousel-control" href="#mini-carousel" role="button" data-slide="prev">
                <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
                <span class="sr-only">Previous</span>
            </a>
            <a class="right carousel-control" href="#mini-carousel" role="button" data-slide="next">
                <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
                <span class="sr-only">Next</span>
            </a>
          </div>
        <?php endif; ?>
</section>

<script>
jQuery(document).ready(function($) {
    $('#mini-carousel').carousel({
      interval: 6000
    });
    $('.fancybox').fancybox({
        padding: 0
    });
});
</script>