Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1305645

    Hi Ismael,

    you suggested this code here to select the masonry categorie.

    You can use this snippet in the functions.php file instead of the previous one.

    add_action('wp_footer', 'ava_auto_click');
    function ava_auto_click() {
    	if(!$_GET["psort"]) return;	
    ?>
    		<script>
            (function($){	
                $(window).load(function() {
    <?php echo '$(".'. $_GET["psort"] .'_sort_button").trigger("click");'; ?>
                });	
            })(jQuery);
            </script>
    <?php
    }

    Unfortunatly this doesn’t work. Either on the same page as well as linking from another page.

    The links are called from an element. Even if I now reload the page it doesn’t work.
    What did you mean with – You may need to add a click event listener to the menu items manually. Please feel to open a new thread if you need further assistance.?

    #1305764

    I turned off the Lazy Loading and migrate jQuery setting and know when I land on the page there is nothing selected. When I reload the page it works.

    How do I add a click event listener to the menu items manually?
    Best Regards
    Rolf

    #1305822

    Hi,

    Thank you for the inquiry.

    The snippet is not working correctly because window.load function is no longer valid. Please try to replace the snippet with this one.

    
    // activates a sort button based on the psort query parameter
    function ava_activate_sort_button() {
    	if(!$_GET["psort"]) return;	
    ?>
    		<script>
            (function($){	
                $(document).ready(function() {
                   <?php echo '$(".'. $_GET["psort"] .'_sort_button").trigger("click");'; ?>
                });	
            })(jQuery);
            </script>
    <?php
    }
    add_action('wp_footer', 'ava_activate_sort_button');
    

    Best regards,
    Ismael

    #1305836

    Thank you for answering.

    I replaced the function with your new one, but unfortunatly it now does not have anything selected anymore. Not even if I reload the page.

    Please try for yourself.

    I also didn’t find a way to set a default preselected category in the masonry code.

    That might be a help too.

    Best regards,
    Rolf

    #1306033

    Hi,

    Thank you for the update.

    It seems to be working properly on our end. We visited the link above with the psort parameter and the script activated the corresponding sort button properly. Please check the screenshot below.

    Screenshot: https://imgur.com/Q5ng7pF

    We did not have to refresh the page.

    Best regards,
    Ismael

    #1306035

    I put back the old code for the customer to see. It seems to work now. Thank you.
    Do you know how to set a default category as selected?

    #1306584

    Hi,

    Glad to know that it is now working.

    To select a default category, you can add this code above the other line with the trigger function.

    $("name_of_category_sort_button").trigger("click");
    

    Just replace the placeholder with the actual name.

    Best regards,
    Ismael

    #1306735

    Thank you for your help!

    #1307085

    Hi,

    No problem. Please feel free to open another thread if you need anything else.

    Have a nice day.

    Best regards,
    Ismael

Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘Direct link to masonry category’ is closed to new replies.