• Resolved sandrinebud

    (@sandrinebud)


    Hello, and thanks a lot for your plugin!
    I’m using it to display my projects, which are organized by category.
    I have managed to customize one carousel using the add_filter code and got the result I’m looking for.
    But my code targets only one carousel (by ID) and I need to use that same model for several carousels, one in each category page. Is this possible?
    I’m not a programer, and I tried my best but I’m stuck right now.
    And I’m french, so I hope I’m being clear in my request ??

    Any chance you could help?
    Thank you so much for your response.

    Here is the code I use:

    add_filter('dd_filter_owl_carousel_script', 'custom_owl_carousel_filter', 10, 2);
    function custom_owl_carousel_filter($owl_script, $carousel_id){
        if ($carousel_id !== 762) return $owl_script;
        $owl_script =" 
            jQuery(function($){
            $('#carousel-762').owlCarousel({
    	        'autoWidth' :true,
                    'loop':true,
                    'autoplay' : false,
                    'autoplayTimeout' : 2000,
                    'smartSpeed' : 400,
                    'fluidSpeed' : 400,
                    'autoplaySpeed' : 400,
                    'navSpeed' : 400,
                    'dotsSpeed' : 400,
                    'margin': 400,
                    'autoplayHoverPause' : false,
                    'center' : false,
                    'responsiveRefreshRate' : 200,
                    'slideBy' : 1,
                    'mergeFit' : true,
                    'mouseDrag' : true,
                    'touchDrag' : true,
                    'nav' : false,
                    'navText' : ['',''],
                    'dots' : false,
                    'lazyLoad' : true,
                    'responsive':{
                        0:{items:1},
                        480:{items:1},
                        768:{items:1},
                        991:{items:1},
                        1200:{items:1},
                        1500:{items:1},
                        },
                    });
                });
            ";
        return $owl_script;
    }
Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author thehowarde

    (@thehowarde)

    I believe this exposes a potential error on my part where the carousel ID may actually be a string instead of an integer. You can try putting quotes around the carousel ID number in the filter. I’ll look at coming up with a more permanent solution however.

    Thread Starter sandrinebud

    (@sandrinebud)

    Thanks for your quick reply.
    Adding quotes around the carousel ID number didn’t work though.
    I ended up with a blank page.

    Thank you anyway, I’ll see if I can come up with another solution.

    Plugin Author thehowarde

    (@thehowarde)

    I guess I don’t understand what your issue is… when you say, “One for each category page” is it the same carousel, or different? What kind of category?

    Thread Starter sandrinebud

    (@sandrinebud)

    I have different projects that I affect to categories I created (wallpaper, rugs, drawings…).
    Then I create one page per category where I want the projects that belong to that category to show in a carousel (that I customized), using taxonomy.
    For instance: https://www.sand-studio.fr/risbourg/wallpaper/

    I need to reproduce the carousel on that page for the other pages (https://www.sand-studio.fr/risbourg/rugs for instance). So the carousel won’t have the same ID. But I need it to have the same look and behavior as the one on the wallpaper page.

    I’m hoping I’m clear in my explanations…

    Plugin Author thehowarde

    (@thehowarde)

    So can’t you just create new carousels? It sounds like you just want this plugin to do something it doesn’t?

    Thread Starter sandrinebud

    (@sandrinebud)

    I did try, believe me.
    I created new carousels, but I can’t find a way to have them behave like the first one, because the add_filter in functions.php targets only the first carousel (using the carousel ID).
    So my question is: is it possible to modify the code of the add_filter so I can use it for several carousels? or is it possible to duplicate the add_filter for each new carousel?
    I appreciate you taking the time to answer me, but I feel like we’re not understanding each other. I’m sorry I’m not a developer, I really try my best here.

    Plugin Author thehowarde

    (@thehowarde)

    Yeah… Just remove this

    if ($carousel_id !== 762) return $owl_script;

    Then it works for all carousels.

    Thread Starter sandrinebud

    (@sandrinebud)

    Ok a friend of mine got me the solution.
    I’ll share it with you, in case you have this request in the future:

    1/ delete the condition : if ($carousel_id !== 762) return $owl_script;
    2/ replace $(‘#carousel-762’).owlCarousel({ by $(‘#carousel-‘+$carousel_id).owlCarousel({`

    So you have:

    add_filter('dd_filter_owl_carousel_script', 'custom_owl_carousel_filter', 10, 2);
    function custom_owl_carousel_filter($owl_script, $carousel_id){
        $owl_script =" 
            jQuery(function($){
    		$('#carousel-'+$carousel_id).owlCarousel({
    Thread Starter sandrinebud

    (@sandrinebud)

    Oups, our messages have crossed ??
    So we’re ok.

    Thanks again.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Add same filter for several carousels’ is closed to new replies.