Last active
March 22, 2023 19:00
-
-
Save KittenCodes/89bd3ac17d35a7d90c1b876356f637b6 to your computer and use it in GitHub Desktop.
Get images from ACF gallery in a Oxygen Repeater when the datasource is an ACF Repeater and add a lightbox to the Gallery
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
/* | |
* Add this to the CSS tab of the Code Block ABOVE the Repeater: | |
*/ | |
.thumbnail img { | |
box-sizing: border-box; | |
border: 1px solid #ddd; | |
padding: 2px; | |
margin: 0 1% 15px 0; | |
width: 32.6667%; | |
display: inline-block; | |
} | |
.thumbnail img:nth-of-type(3n+3) { | |
margin-right: 0; | |
} |
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
// Add this to the JavaScript tab of the Code Block ABOVE the Repeater: | |
jQuery(document).ready(function(){ | |
jQuery('.gallery').slickLightbox({ | |
itemSelector: '> a' | |
}); | |
}); |
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
// Add this to the PHP & HTML tab of a Code Block ABOVE the Repeater: | |
<?php | |
session_start(); | |
$_SESSION['row_index'] = 0; | |
?> |
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
// Add this to the PHP & HTML tab of a Code Block INSIDE the Repeater. Asjust the field names as needed. | |
<?php | |
// This is your Repeater field name | |
$rows = get_field('elements-repeater' ); | |
$specific_row = $rows[$_SESSION['row_index']]; | |
// This is the Gallery field name | |
$gallery_images = $specific_row['gallery_of_photos']; | |
if($gallery_images): ?> | |
<div class="gallery"> | |
<?php foreach( $gallery_images as $image ): ?> | |
<a href="<?php echo $image['url']; ?>" target="_blank" class="thumbnail"> | |
<img src="<?php echo $image['sizes']['medium']; ?>" alt="<?php the_title(); ?>" /> | |
</a> | |
<?php endforeach; ?> | |
</div> | |
<?php endif; ?> | |
<?php | |
$_SESSION['row_index'] ++; | |
?> |
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
Add this to the Code Snippets plugin: https://en-gb.wordpress.org/plugins/code-snippets/ | |
<?php | |
add_action( 'wp_enqueue_scripts', 'enqueue_slick_files' ); | |
/** | |
* Loads <list assets here>. | |
*/ | |
function enqueue_slick_files() { | |
// Enqueue CSS | |
wp_enqueue_style( 'slick-css', '/gallery/slick.css' ); | |
wp_enqueue_style( 'slick-theme', '/gallery/slick-theme.css' ); | |
wp_enqueue_style( 'slick-lightbox', '/gallery/slick-lightbox.css' ); | |
// Enqueue JS | |
wp_enqueue_script( 'slick-js', '/gallery/slick.min.js', '', '', true ); | |
wp_enqueue_script( 'slick-lightbox-js', '/gallery/slick-lightbox.js', '', '', true ); | |
} | |
?> |
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
Extract the "gallery" directory from the ZIP file here and put it in the site root: https://d.pr/f/y7Q1Uh | |
Follow the instructions in the other files in this Gist so that you know where to put the code. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment