Last active
December 9, 2023 10:30
-
-
Save hssktm/2f5e84b85ed6e3e14359de3b8e466715 to your computer and use it in GitHub Desktop.
Gallery ACF + Repeater Oxygen Builder
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
//*******Lightbox***********/ | |
function load_glightbox_scripts() { | |
if (!is_admin()) { | |
wp_enqueue_style('glightbox-css', 'https://cdn.jsdelivr.net/npm/glightbox/dist/css/glightbox.min.css'); | |
wp_enqueue_script('glightbox-js', 'https://cdn.jsdelivr.net/gh/mcstudios/glightbox/dist/js/glightbox.min.js', array('jquery'), null, true); | |
} | |
} | |
add_action('wp_enqueue_scripts', 'load_glightbox_scripts'); | |
//*******Js Code Block***********/ | |
document.addEventListener('DOMContentLoaded', function() { | |
const lightbox = GLightbox({ | |
touchNavigation: true, | |
loop: true, | |
autoplayVideos: true, | |
selector: '.lightbox' | |
}); | |
}); | |
//*******Repeater Gallery ACF***********/ | |
function repeater_gallery_results($categories, $query) { | |
if ('anynon-commonname' == $query->get('post_type')) { | |
$categories = array(); | |
$images = get_field('gallery_imagesds'); //Name Gallery ACF | |
$size = 'full'; // Specify the image size you want. | |
if ($images) { | |
foreach ($images as $image_id) { | |
$image_data = (object) array( | |
'image_id' => $image_id, // Image ID. | |
'post_content' => '', // Placeholder for post content. | |
'title' => get_the_title($image_id), // Image Title. | |
'caption' => get_post($image_id)->post_excerpt,// Image Caption. | |
'alt_text' => get_post_meta($image_id, '_wp_attachment_image_alt', true), // Image Alt Text. | |
'description' => get_post($image_id)->post_content, // Image Description. | |
'image_url' => wp_get_attachment_image_src($image_id, $size)[0], // Image URL. | |
); | |
$categories[] = $image_data; | |
} | |
} | |
} | |
return $categories; | |
} | |
add_filter('the_posts', 'repeater_gallery_results', 10, 2); | |
function custom_field($value) { | |
global $post; | |
return $post->$value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment