Archived topic
Pagination jumps to top of page
3 replies · Started by Chris on January 19, 2023
I have a static (home) page with a query loop below other content.
Of course, if someone increments the query loop, they jump to the top of the page and have to scroll down to get to the query loop section. It's an awkward experience.
I found one post where Tom mentioned a bit of code that would return the user to the same spot on the page and that it might be included in a future version of GP.
Has that been added at this point?
Another potential solution would be a 'load more' button that would load additional posts via ajax, I think Show Posts used to do this? Is that possible with GP? (and if so, is it crawlable by search engines?),
Chris
Hi there,
where can i see the issue ? Can you share a link ?
Is this not the standard/expected behavior?
It's expected behaviour. There's a way to add an ID to the pagenation button's URL, but it will only work for the previous/next button, not the numbers.
The steps:
1. Add an HTML anchor to the grid block nested in the query loop block, eg. my-query.
2. Add additional CSS class to the previous/next button, eg.pagination-button.
3. Add this PHP code:
add_filter('generateblocks_dynamic_url_output','custom_query_loop_pagination', 10,2);
function custom_query_loop_pagination($url , $attributes) {
if( ! empty( $url ) && ! empty( $attributes['className'] ) && 'pagination-button' === $attributes['className'] ) {
$url = $url.'/#my-query';
}
return $url;
}