Load more button (both CSS and shortcode template approaches)

mgibbs189

{{gist file=”test-css-approach.php” lang=”php”}}
<?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>
{{/gist}}{{gist file=”test-shortcode-approach.php” lang=”php”}}
<?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>
{{/gist}}