Last active
April 15, 2016 11:46
-
-
Save mgibbs189/745124f65eb32eec92da to your computer and use it in GitHub Desktop.
Load more button (both CSS and shortcode template approaches)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| CSS-template approach | |
| */ | |
| ?> | |
| <button class="fwp-load-more" onclick="fwp_load_more()">Load more</button> | |
| <script> | |
| (function($) { | |
| $(function() { | |
| FWP.is_load_more = false; | |
| wp.hooks.addFilter('facetwp/template_html', function(result, params) { | |
| if (FWP.loaded && FWP.is_load_more) { | |
| FWP.is_load_more = false; | |
| var inject = $(params.response.template).find('.facetwp-template').html(); | |
| $('.facetwp-template').append(inject); | |
| return true; | |
| } | |
| return false; | |
| }); | |
| }); | |
| })(jQuery); | |
| function fwp_load_more() { | |
| FWP.is_load_more = true; | |
| var page = FWP.settings.pager.page; | |
| var total_pages = FWP.settings.pager.total_pages; | |
| if (page < total_pages) { | |
| FWP.paged = (page + 1); | |
| FWP.refresh(); | |
| } | |
| if (page + 1 == total_pages) { | |
| $('.fwp-load-more').hide(); | |
| } | |
| } | |
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| Shortcode-template approach | |
| */ | |
| ?> | |
| <button class="fwp-load-more" onclick="fwp_load_more()">Load more</button> | |
| <script> | |
| (function($) { | |
| $(function() { | |
| FWP.is_load_more = false; | |
| wp.hooks.addFilter('facetwp/template_html', function(result, params) { | |
| if (FWP.loaded && FWP.is_load_more) { | |
| FWP.is_load_more = false; | |
| var inject = params.response.template; | |
| $('.facetwp-template').append(inject); | |
| return true; | |
| } | |
| return false; | |
| }); | |
| }); | |
| })(jQuery); | |
| function fwp_load_more() { | |
| FWP.is_load_more = true; | |
| var page = FWP.settings.pager.page; | |
| var total_pages = FWP.settings.pager.total_pages; | |
| if (page < total_pages) { | |
| FWP.paged = (page + 1); | |
| FWP.refresh(); | |
| } | |
| if (page + 1 == total_pages) { | |
| $('.fwp-load-more').hide(); | |
| } | |
| } | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello Matt,
Load more button works fine but facet filters not working with this code.
What is the problem?
Thanks.