Created
January 11, 2017 17:06
-
-
Save smutek/50349ff697bd20c8524dee585c8ad59d to your computer and use it in GitHub Desktop.
Synced Sliders. See the synced sliders demo at http://kenwheeler.github.io/slick/ This assumes Advanced Custom Fields repeater is being used, but the concept should work with any data source. Be sure to change out the field names and class names as needed.
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 | |
/* | |
* Synced sliders, | |
* | |
* See the synced sliders example at http://kenwheeler.github.io/slick/ | |
*/ | |
// Make sure there's stuff to display | |
if ( have_rows( 'add_testimonials' ) ) : | |
// We'll hold our slides here. | |
$testimonials = []; | |
// We need to populate 2 separate sliders with info from the same | |
// data set. We'll run have_rows() here, stash the results in an | |
// array, and then use 2 foreach loops to build the markup. This | |
// makes the markup a little cleaner and avoids running have_rows() | |
// twice to retrieve the same information. | |
while ( have_rows( 'add_testimonials' ) ) : the_row(); | |
$testimonial['name'] = get_sub_field( 'testimonial_name' ); | |
$testimonial['title'] = get_sub_field( 'testimonial_title' ); | |
$testimonial['copy'] = get_sub_field( 'testimonial_copy' ); | |
$imageArray = get_sub_field( 'testimonial_image' ); | |
$testimonial['img_url'] = $imageArray['url']; | |
$testimonial['img_alt'] = $imageArray['alt']; | |
$testimonials[] = $testimonial; | |
endwhile; | |
?> | |
<section class="module module-testimonials"> | |
<div id="<?= $id; ?>" class="container"> | |
<div class="testimonial-wrap row"> | |
<div class="col-sm-6 testimonial-content testimonial-images"> | |
<?php foreach ( $testimonials as $testimonial ) : ?> | |
<img class="img-responsive" src="<?= $testimonial['img_url']; ?>" alt="<?= $testimonial['img_alt']; ?>"> | |
<?php endforeach; ?> | |
</div> | |
<div class="col-sm-6 testimonial-content testimonial-copy"> | |
<?php foreach ( $testimonials as $testimonial ) : ?> | |
<blockquote> | |
<?= $testimonial['copy'] ?> | |
<footer> | |
<cite><?= $testimonial['name']; ?> | |
<small><?= $testimonial['title']; ?></small> | |
</cite> | |
</footer> | |
</blockquote> | |
<?php endforeach; ?> | |
</div> | |
</div> | |
</div> | |
</section> | |
<?php endif; // end if have rows |
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
// Assumes slick is already installed. | |
$('.testimonial-images').slick({ | |
slidesToShow: 1, | |
slidesToScroll: 1, | |
arrows: false, | |
fade: true, | |
asNavFor: '.testimonial-copy' | |
}); | |
$('.testimonial-copy').slick({ | |
slidesToShow: 1, | |
slidesToScroll: 1, | |
asNavFor: '.testimonial-images', | |
focusOnSelect: true | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment