Last active
August 19, 2016 21:12
-
-
Save mgibbs189/33fa89e2997f14ac15239ec6a1d0d886 to your computer and use it in GitHub Desktop.
FacetWP - intercept Genesis pagination
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
(function($) { | |
$(document).on('click', '.pagination a', function(e) { | |
e.preventDefault(); | |
var matches = $(this).attr('href').match(/\/page\/(\d+)/); | |
if (null != matches) { | |
FWP.paged = parseInt(matches[1]); | |
} | |
FWP.soft_refresh = true; | |
FWP.refresh(); | |
}); | |
})(jQuery); |
FYI, this breaks the next/previous post links in the Genesis pagination. I dug through a bit and it seems to be due to the fact that they use get_previous_posts_link
and get_next_posts_link
for their next and prev links rather than paginate_links
like the pagination function in core uses.
I messed around with it a little and ended up ditching the Genesis pagination in favor of what's in core, which still works with this and is better in general anyway IMO.
I also ran into the same thing as Mike and handled it by adding scroll( 0, 0 );
after the refresh.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great snippet, this worked right away. It was strangely leaving my screen at the bottom of the page so I added
$('html, body').animate({ scrollTop: 0 }, 'slow');
. Still slightly awkward, but working. Thanks for this.