-
AuthorPosts
-
June 14, 2021 at 4:26 pm #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.?June 15, 2021 at 11:06 am #1305764I 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
RolfJune 15, 2021 at 2:23 pm #1305822Hi,
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,
IsmaelJune 15, 2021 at 4:08 pm #1305836Thank 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,
RolfJune 16, 2021 at 2:43 pm #1306033Hi,
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,
IsmaelJune 16, 2021 at 2:47 pm #1306035I 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?June 20, 2021 at 9:01 pm #1306584Hi,
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,
IsmaelJune 21, 2021 at 2:17 pm #1306735Thank you for your help!
June 23, 2021 at 8:07 am #1307085 -
AuthorPosts
- The topic ‘Direct link to masonry category’ is closed to new replies.