-
AuthorPosts
-
February 22, 2024 at 2:07 am #1435074
Can someone please help? I am looking for a code or a way to stop accordion sliders from displaying all images on the page. I want the accordion slider to only show the images in that specific slider. It seems as though whenever I am viewing images in a lightbox the lightbox allows me to click left or right through every picture on the page. I do not want that to happen with the accordion sliders. Especially with the iframe I created. I don’t want to be able to click left or right when I open up the “Quick Quote” iframe on all of my pages. Please look at the About Us page as well, I don’t want to open up the 1890-1950s accordion slider and be able to see images from the 1950-2000 or even the pas/present article image. Why is it showing every single picture on that page in the lightbox? Please help.
February 22, 2024 at 7:40 pm #1435150You could set the grouping manually, using custom classes in combination with scripts in functions.php; in general, however, it is sufficient to keep the corresponding elements within a color section. And then set a new section for the next element.
Unfortunately I can’t see your page to give better advice.February 22, 2024 at 7:59 pm #1435152Hmm, it sounds good, how would I do that? You can look at the site here: moircrane.com
February 23, 2024 at 8:37 am #1435166Hi,
Thank you for the inquiry.
As suggested above, you can apply a custom class name to the Accordion elements and re-initialize the lightbox script in order to group the items. Please edit all Accordion elements in the page, then go to the Advanced > Developer Settings. In the Custom CSS Class name field, place the value ‘accordion-lightbox-group’. After editing all Accordion elements, add this code in the functions.php file.
function ava_custom_script_group_lightbox() { ?> <script> (function($){ function g() { var accordion = $('.accordion-lightbox-group') accordion.each(function() { var srcList = []; var slider = $(this) slider.find('li a').each(function() { var src = $(this).attr('href'); var title = $(this).attr('title'); var alt = $(this).attr('alt'); srcList.push({ src: src, type: 'image', title: title, alt: alt }); }); slider.magnificPopup({ items: srcList, type: 'image', gallery: {enabled: true} }); }); } $(document).ready(function() { g(); }); })(jQuery); </script> <?php } add_action('wp_footer', 'ava_custom_script_group_lightbox');
If this doesn’t work as expected, try to edit the enfold/js/avia-snippet-lightbox.js, look for this code:
var alt = item.el.attr('alt'); if (typeof alt == "undefined") { alt = item.el.find('img').attr('alt'); } if (typeof alt != "undefined") { img.attr('alt', alt); }
Replace it with:
if (item.el) { var alt = item.el.attr('alt'); if (typeof alt == "undefined") { alt = item.el.find('img').attr('alt'); } if (typeof alt != "undefined") { img.attr('alt', alt); } }
Best regards,
IsmaelFebruary 23, 2024 at 2:33 pm #1435202
See screenshots above. Looks like the code for functions.php is not letting me add it. Please advise?
February 23, 2024 at 3:16 pm #1435214yes – where is the leading:
function ava_custom_script_group_lightbox()
on : link
February 23, 2024 at 3:27 pm #1435216Its there, the first line, but its hidden because of the amount of stuff allowed to show on the screen at once.
February 23, 2024 at 3:30 pm #1435218February 23, 2024 at 4:53 pm #1435227i could not test it now if it works – but the code from : https://kriesi.at/support/topic/accordion-slider-stop-allowing-all-images-to-show-in-slider/#post-1435166 does not lead to a functions.php error on my end here – means – the syntax is o.k.
February 23, 2024 at 5:11 pm #1435233Yeah I tired in another website I have and it worked. I’m not sure what is wrong with this file?
February 23, 2024 at 5:21 pm #1435234If you use the same function name more than once (ava_custom_script_group_lightbox), an error is also displayed – but with a different message. Function names must be unique.
btw. i would have finished the variable setting with a semicolon – but as said above – no error on using it without.
var accordion = $('.accordion-lightbox-group') ;
February 23, 2024 at 5:51 pm #1435241I added it through the cpanel, and its in there now but I don’t see the code working to accomplish what I am looking for?
February 23, 2024 at 7:10 pm #1435246Just want to make sure I’m adding the custom css correctly? I have added this to each accordion slider on the site, in the same location on all of them.
February 24, 2024 at 2:23 pm #1435291Moderators? I’m still looking for help on getting this working?
February 24, 2024 at 8:47 pm #1435313Hi,
Please give this a try, add this code to the end of your child theme functions.php file in Appearance ▸ Editor:function group_lightbox_images(){ ?> <script> (function($){ $(window).on('load', function() { $('.lightbox-added').each(function() { var parentClass = $(this).closest('[class*="group-"]').attr('class'); if (parentClass) { var match = parentClass.match(/group-(\d+)/); if (match && match[1]) { $(this).attr('data-group', match[1]); } } }); var groups = {}; $('.lightbox-added').each(function() { var id = parseInt($(this).attr('data-group'), 10); if (!groups[id]) { groups[id] = []; } groups[id].push(this); }); $.each(groups, function() { $(this).magnificPopup({ type: 'image', mainClass: 'avia-popup mfp-zoom-in mfp-image-loaded', closeOnContentClick: false, closeBtnInside: false, gallery: { enabled: true } }); }); }); })(jQuery); </script> <?php } add_action('wp_footer', 'group_lightbox_images');
If you are not using a child theme you could use the WP Code plugin then add a new snippet, in the top right corner use the PHP snippet as the code type:
then add the above code and save.
Then add the custom class group-1 to each accordion slider, changing the number for each one, ie: group-2, group-3, etc.
Then when the image in any group is opened only the other images in the same group will show.Best regards,
MikeFebruary 24, 2024 at 9:52 pm #1435319You are a genius!!! thank you so much!!! It works perfectly!
February 24, 2024 at 10:24 pm #1435321Hi,
Glad we were able to help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.Best regards,
Mike -
AuthorPosts
- The topic ‘Accordion Slider – Stop allowing all images to show in slider’ is closed to new replies.