Viewing 17 posts - 1 through 17 (of 17 total)
  • Author
    Posts
  • #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.

    #1435150

    You 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.

    #1435152

    Hmm, it sounds good, how would I do that? You can look at the site here: moircrane.com

    #1435166

    Hi,

    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,
    Ismael

    #1435202

    functions.php
    js/avia-snippet-lightbox.js

    See screenshots above. Looks like the code for functions.php is not letting me add it. Please advise?

    #1435214

    yes – where is the leading:
    function ava_custom_script_group_lightbox()

    on : link

    #1435216

    Its there, the first line, but its hidden because of the amount of stuff allowed to show on the screen at once.

    #1435218

    functions.php

    #1435227

    i 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.

    #1435233

    Yeah I tired in another website I have and it worked. I’m not sure what is wrong with this file?

    #1435234

    If 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') ;

    #1435241

    I 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?

    #1435246

    Custom CSS

    Just 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.

    #1435291

    Moderators? I’m still looking for help on getting this working?

    #1435313

    Hi,
    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:
    Enfold_Support_2680.jpeg
    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.
    Enfold_Support_4803.jpeg
    Then when the image in any group is opened only the other images in the same group will show.

    Best regards,
    Mike

    #1435319

    You are a genius!!! thank you so much!!! It works perfectly!

    #1435321

    Hi,
    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

Viewing 17 posts - 1 through 17 (of 17 total)
  • The topic ‘Accordion Slider – Stop allowing all images to show in slider’ is closed to new replies.