Last active
October 12, 2021 03:09
-
-
Save neilgee/d4a4c1c3de098cc34cad34208f6158e7 to your computer and use it in GitHub Desktop.
Bootstrap carousel ACF Repeaters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Bootstrap Carousel Slider Repeater | |
*/ | |
// *Repeater | |
// carousel_repeater | |
// *Sub-Fields | |
// carousel_image | |
// carousel_text | |
// check if the repeater field has rows of data | |
if( have_rows('carousel_repeater') ): | |
$i = 0; // Set the increment variable | |
echo '<div id="carouselExampleSlidesNav4" class="carousel slide" data-ride="carousel"> | |
<ol class="carousel-indicators">'; | |
// loop through the rows of data for the tab header | |
while ( have_rows('carousel_repeater') ) : the_row(); | |
?> | |
<li data-target="#carouselExampleSlidesNav4" data-slide-to="<?php echo $i;?>" class="<?php if($i == 0) echo 'active';?>"></li> | |
<?php $i++; // Increment the increment variable | |
endwhile; //End the loop | |
echo '</ol> | |
<div class="carousel-inner">'; | |
// loop through the rows of data for the tab header | |
$i = 0; // Set the increment variable | |
while ( have_rows('carousel_repeater') ) : the_row(); | |
$image = get_sub_field('carousel_image'); | |
$text = get_sub_field('carousel_text'); | |
?> | |
<div class="carousel-item <?php if($i == 0) echo 'active';?>"> | |
<img class="d-block w-100" src="<?php echo $image['url']; ?>" alt="<?php echo $image['title']; ?>"> | |
<div class="carousel-caption d-block"> | |
<h2><?php echo $text; ?></h2> | |
</div> | |
</div> | |
<?php $i++; // Increment the increment variable | |
endwhile; //End the loop | |
echo '</div> | |
<a class="carousel-control-prev" href="#carouselExampleSlidesNav4" 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="#carouselExampleSlidesNav4" role="button" data-slide="next"> | |
<span class="carousel-control-next-icon" aria-hidden="true"></span> | |
<span class="sr-only">Next</span> | |
</a> | |
</div>'; | |
else : | |
// no rows found | |
endif; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// *Repeater | |
// carousel_repeater | |
// *Sub-Fields | |
// carousel_image | |
// carousel_text | |
// check if the repeater field has rows of data | |
if( have_rows('carousel_repeater') ): | |
echo '<div id="carouselExamplethumbs" class="carousel slide" data-ride="carousel"> | |
<div class="carousel-inner">'; | |
// loop through the rows of data for the tab header | |
$i = 0; // Set the increment variable | |
while ( have_rows('carousel_repeater') ) : the_row(); | |
$image = get_sub_field('carousel_image'); | |
$text = get_sub_field('carousel_text'); | |
?> | |
<div class="carousel-item <?php if($i == 0) echo 'active';?>"> | |
<img class="d-block w-100" src="<?php echo $image['url']; ?>" alt="<?php echo $image['title']; ?>"> | |
<div class="carousel-caption d-block"> | |
<?php echo $text; ?> | |
</div> | |
</div> | |
<?php $i++; // Increment the increment variable | |
endwhile; //End the loop | |
echo '</div>'; | |
$i = 0; // Set the increment variable | |
echo '<ol class="carousel-indicators position-relative">'; | |
// loop through the rows of data for the tab header | |
while ( have_rows('carousel_repeater') ) : the_row(); | |
$image = get_sub_field('carousel_image'); | |
$text = get_sub_field('carousel_text'); | |
?> | |
<li class="w-100 h-100" style="text-indent:0" data-target="#carouselExamplethumbs" data-slide-to="<?php echo $i;?>" class="<?php if($i == 0) echo 'active';?>"><img src="<?php echo $image['url']; ?>" /></li> | |
<?php $i++; // Increment the increment variable | |
endwhile; //End the loop | |
echo '</ol>'; | |
echo '<a class="carousel-control-prev" href="#carouselExamplethumbs" 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="#carouselExamplethumbs" role="button" data-slide="next"> | |
<span class="carousel-control-next-icon" aria-hidden="true"></span> | |
<span class="sr-only">Next</span> | |
</a> | |
</div>'; | |
else : | |
// no rows found | |
endif; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// *Repeater | |
// carousel_repeater | |
// *Sub-Fields | |
// carousel_image | |
// carousel_text | |
// check if the repeater field has rows of data | |
if( have_rows('carousel_repeater') ): | |
$i = 1; // Set the increment variable | |
echo '<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel"> | |
<div class="carousel-inner">'; | |
// loop through the rows of data for the tab header | |
while ( have_rows('carousel_repeater') ) : the_row(); | |
$image = get_sub_field('carousel_image'); | |
$text = get_sub_field('carousel_text'); | |
?> | |
<div class="carousel-item <?php if($i == 1) echo 'active';?>"> | |
<img class="d-block w-100" src="<?php echo $image['url']; ?>" alt="<?php echo $image['title']; ?>"> | |
</div> | |
<?php $i++; // Increment the increment variable | |
endwhile; //End the loop | |
echo '</div> | |
</div>'; | |
else : | |
// no rows found | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you, bro