Last active
March 23, 2021 17:51
-
-
Save morgyface/b4b64e4ae27dcdf229b4d9449fc3adf3 to your computer and use it in GitHub Desktop.
Testimonial carousel | Wordpress | ACF | Bootstrap
This file contains 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 | |
if( have_rows('testimonials') ): | |
echo '<div id="testimonials" class="carousel slide" data-ride="carousel" data-pause="false">'; | |
echo '<div class="carousel-inner">'; | |
$count = 1; | |
while( have_rows('testimonials') ): the_row(); | |
$testimonial = get_sub_field('testimonial_text'); | |
$author = get_sub_field('testimonial_author'); | |
echo '<div class="carousel-item text-center py-5'; | |
if ( $count == 1 ) { | |
echo ' active'; // Add the active class to the first row | |
} | |
echo '">' . PHP_EOL; | |
echo '<blockquote class="w-50 mx-auto my-0 py-5">'; | |
echo '<p class="h1 mb-5">“' . $testimonial . '”</p>'; | |
if ( $author ) { | |
$role = get_sub_field('testimonial_role'); | |
echo '<hr>'; | |
echo '<footer><cite>' . $author; | |
if ( $role ) { | |
echo '<br>' . $role; | |
} | |
echo '</cite></footer>'; | |
} | |
echo '</blockquote>'; | |
echo '</div>'; // Close .carousel-item | |
$count++; // So we can establish the first post and attach the mandatory active class | |
endwhile; | |
echo '</div>'; // Close .carousel-inner | |
echo '</div>'; // Close .carousel | |
endif; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A testimonial slider using Wordpress, ACF and Bootstrap
We use an Advanced Custom Fields Repeater named testimonials, with sub fields of testimonial_text, testimonial_author, testimonial_role.
A note; applying bootstrap padding to carousel-inner results in a vertical shift on the slide and is best avoided.