Home › Forums › Support › Query loop pagination, any way to reload in place if a query loop is lower down?
- This topic has 16 replies, 5 voices, and was last updated 4 months, 2 weeks ago by
David.
-
AuthorPosts
-
October 4, 2022 at 7:44 am #2362719
Gary
Hi Support
I have a GB query loop on a standard page which requires pagination and is used further down below the fold on this particular page. The pagination works but it naturally returns the user to the top of the page which takes the user out of the flow of scanning through articles and requires them to scroll further down the page again. I was therefore wondering if there’s any way I could deal with this currently?
Thinking maybe a filter or something that I could utilise to adapt the default pagination block to return them to the same anchor point on the page?
Thanks
October 4, 2022 at 11:44 am #2363167Ying
StaffCustomer SupportHi Gary,
Can you link me to the page?
October 5, 2022 at 2:02 am #2363787Gary
Hi Ying
Thanks for the reply, I’ve supplied the link to page in question in the private info.
October 5, 2022 at 9:21 am #2364321Tom
Lead DeveloperLead DeveloperHey Gary,
We might be able to do something… Let’s try this:
1. Give your Next button a custom class. Something like:
custom-next
2. Add this PHP:add_filter( 'generateblocks_dynamic_url_output', function( $url, $attributes ) { if ( ! empty( $attributes['className'] ) && 'custom-next' === $attributes['className'] ) { $url = $url . '#my-loop-id'; } return $url; }, 10, 2 );
3. Add a Container (or any element) around your loop, and give it the ID you specified in the function:
my-loop-id
Let me know if that works or not π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentOctober 6, 2022 at 4:24 am #2365031Gary
Hi Tom
Thanks so much for looking in to this. I’ll give the suggested code a try and let you know if it works.
Cheers
October 6, 2022 at 4:54 am #2365061Gary
Hi Tom
This worked really well, I just tweaked your original snippet slightly so that it also checks whether the url has a value. Without this the previous & next links were still being filtered at the beginning or end of the loop and being shown rather than hidden:
add_filter( 'generateblocks_dynamic_url_output', function( $url, $attributes ) { if ( ! empty( $url ) && ! empty( $attributes['className'] ) && 'custom-prev-next' === $attributes['className'] ) { $url = $url . '#blog-posts'; } return $url; }, 10, 2 );
It also didn’t work with the pagination numbers for some reason? So I removed those and just had previous/next links which is fine for my use case but thought I should mention that in case anyone else is looking to do something similar.
Thanks again π
October 6, 2022 at 6:30 pm #2365746Tom
Lead DeveloperLead DeveloperNo problem! I’m glad it worked. I’ll take a look to see why it didn’t work with the numbers – this seems like a useful feature to include in the plugin.
Thanks!
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentNovember 3, 2022 at 4:09 am #2399738Friedhelm
Dear Tom,
I also have 2 query loops on one page. It will soon be my home page (see test page). The loop below needs the pagination block, so I also included Gary’s snippet (so that the visitor clicks on to the beginning of the loop), it works quite well so far. But with my more than 1000 posts, you should also get to the beginning of the loop when you click on the page numbers.
I would really appreciate it if this function was added to the query loop in the next update. Do you perhaps have an idea how the above snippet could be supplemented in the meantime?
I would be pleased if you would deal with this topic again.
Sending greetings from BerlinFriedhelm
November 3, 2022 at 5:12 am #2399853David
StaffCustomer SupportHi there,
the Query Loop Post Navigation is made of 3 blocks: Previous, Pagination and Next – if you give each of them the same custom class Eg. ‘jump-link’
then you can use the one filter to target that class to add the jump link:
add_filter( 'generateblocks_dynamic_url_output', function( $url, $attributes ) { if ( ! empty( $url ) && ! empty( $attributes['className'] ) && 'jump-link' === $attributes['className'] ) { $url = $url . '#blog-posts'; } return $url; }, 10, 2 );
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/November 3, 2022 at 10:12 am #2400406Friedhelm
Dear David,
Unfortunately, the snippet does not work as intended with “pagination”: For example: anchor “blog-post”, loop is on page 5:
With mouse over the link appears:
at Previous: ……. /?query-e222b277-page=4&cst#blog-posts
at pagination: … /?query-e222b277-page=6&cst
at Next: β¦………. /?query-e222b277-page=6&cst#blog-postsIn the case of pagination, the information on the anchor is missing; that means here there is no jump to the anchor, but the jump to the top of the page (although all 3 blocks: Previous, Pagination and Next have the same CSS class “jump-link”). (see test page)
So I would like to ask you again: Do you perhaps have an idea how the above snippet could be supplemented? I would be happy if you would find a solution.
Friedhelm
November 4, 2022 at 2:51 am #2401132David
StaffCustomer SupportOk, for the pagination buttons only try this instead:
add_filter( 'generateblocks_dynamic_url_output', function( $url, $attributes ) { if ( ! empty( $url ) && ! empty( $attributes['className'] ) && 'paging-jump-link' === $attributes['className'] ) { $url = $url . '&var=var#blog-posts'; } return $url; }, 10, 2 );
Note the class for the paging buttons has been updated in the code to
paging-jump-link
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/November 4, 2022 at 7:33 am #2401504Friedhelm
Dear David,
I was hoping, but unfortunately the snippet for the pagination buttons doesn’t work either. It is the same result as described in my last post (see there). Do you perhaps have another idea?Friedhelm
November 4, 2022 at 9:11 am #2401840David
StaffCustomer SupportSorry – i just wasted your time.
Thatfilter
isn’t present on the paging buttons. So thats why it don’t work…. apologies twice as we don’t have a solution apart from resorting to JavascriptFor now you would have to disable the pagination ….
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/November 5, 2022 at 2:05 am #2402398Friedhelm
OK, David, thank you for your efforts. Then I have to live with it for the time being.
I would appreciate it if you found a solution for the pagination buttons in the next update: make it possible to jump to the beginning of the loop.
Friedhelm
November 6, 2022 at 3:42 am #2403366David
StaffCustomer SupportIts on our list π We’ll look to resolve asap!!
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.