Guest User

Breakdance - Multiple galleries lightbox fix - Code Block

a guest
Feb 17th, 2026
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | Source Code | 0 0
  1. {"element":{"id":103,"data":{"type":"EssentialElements\\CodeBlock","properties":{"content":{"content":{"php_code":"<?php\n\nadd_action('wp_enqueue_scripts', function() {\n // Core\n wp_enqueue_style('lightgallery', 'https://cdn.jsdelivr.net/npm/lightgallery@2/css/lightgallery-bundle.min.css');\n wp_enqueue_script('lightgallery', 'https://cdn.jsdelivr.net/npm/lightgallery@2/lightgallery.umd.js', [], null, true);\n\n // Plugins\n wp_enqueue_script('lg-thumbnail', 'https://cdn.jsdelivr.net/npm/lightgallery@2/plugins/thumbnail/lg-thumbnail.umd.js', ['lightgallery'], null, true);\n wp_enqueue_script('lg-zoom', 'https://cdn.jsdelivr.net/npm/lightgallery@2/plugins/zoom/lg-zoom.umd.js', ['lightgallery'], null, true);\n wp_enqueue_script('lg-fullscreen', 'https://cdn.jsdelivr.net/npm/lightgallery@2/plugins/fullscreen/lg-fullscreen.umd.js', ['lightgallery'], null, true);\n});","javascript_code":"const galleryContainer = document.querySelector('.ee-gallery--multiple');\n\ngalleryContainer.addEventListener('click', function(e) {\n const clickedItem = e.target.closest('a.ee-gallery-item');\n if (!clickedItem) return;\n\n e.preventDefault();\n e.stopPropagation();\n\n // Get the active category from the clicked item\n const activeCategory = clickedItem.getAttribute('data-category');\n\n // Build slides from items in the same category\n const categoryItems = galleryContainer.querySelectorAll(\n 'a.ee-gallery-item[data-category=\"' + activeCategory + '\"]'\n );\n\n const slides = [];\n let startIndex = 0;\n\n categoryItems.forEach(function(item, i) {\n if (item === clickedItem) startIndex = i;\n\n slides.push({\n src: item.href,\n thumb: item.querySelector('img').src,\n subHtml: item.getAttribute('data-sub-html') || ''\n });\n });\n\n // Open lightbox with only this category's images\n const lg = lightGallery(document.createElement('div'), {\n dynamic: true,\n dynamicEl: slides,\n plugins: [lgThumbnail, lgZoom, lgFullscreen],\n index: startIndex,\n speed: 300,\n thumbnail: true,\n animateThumb: true,\n loop: true,\n download: false\n });\n\n lg.openGallery(startIndex);\n});","builder_label":"Lightbox.js Code"}}}},"children":[],"_parentId":106}}
Advertisement
Add Comment
Please, Sign In to add comment