-
Davidr
Hello, I wanted to ask you a question, I don’t know if it’s possible. I would like that when using the elements “previous page, next page”, the arrows. Would it be possible that when doing the loop query, it does not return the next page at the top of the header? I would like the loop to not have to reload the top. I have built it with 2 parts of elements a hook for the top color highlight (Block – Hook generate_after_header) and the blog loop in (Block – Loop Template)
capture:
https://ibb.co/BNBkMbB -
David
Hi there,
it would require 2 things:
1. the Query Loop should be set to
Inherit Query from Template
and that way the Post Navigation will use template pagination.2. then you can use a PHP Snippet to disable the top highlight element on paged instances:
add_filter( 'generate_element_display', function( $display ) { if ( 99 === $element_id && is_paged() ) { $display = false; } return $display; } );
Change the
99
to the ID of the Element you need to remove. -
Davidr
Thank you, but this is not exactly what I wanted, I “rolled up” when explaining myself. What I wanted to achieve is that the loop of, for example, page 2, does not reload the page again from the header but from the “latest news” section, so that it does not make the jump this annoying having to go back down with each load of the “turn the page”, I don’t know if I have explained myself better this time, sorry.
-
So you want when the paged page is loaded, it will scroll to the “latest news”section?
It’s not possible to add HTML anchor to the numbered pagination buttons, but it’s possible to add it to the previous and next page buttons of the query loop pagination.
Otherwise, custom Javascript is required to change the pagination URLs.
-
Davidr
If I have it built with the “previous and next page” buttons, typical of the query loop, could you tell me how I can build it? I’ll give you an example video to better clarify the idea of what I want to achieve. THANK YOU
https://ibb.co/17Y9P1r -
Fernando
Hi Davidr,
Let’s try this:
1. Give your Next button a custom class. Something like:
custom-next
.Adding Custom Classes: https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/
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 );
Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
3. Add a Container (or any element) around your loop, and give it the anchor ID you specified in the function/code in #2:
my-loop-id
Let us know if that works or not.
-
Davidr
It worked perfectly, thank you very much. One question, why would you suggest a plugin for adding php fragments, this could not be created with the “elements/hook” of generatepress itself.?
-
David
GP Elements use Action Hooks to insert content ( and should only be used to insert content ) into frontend templates and template parts.
Those hooks are executed after front end templates are loaded which is much later in the WP code execution cycle.
Snippets such as the one above uses a filter hook, and should be registered earlier in the cycle eg. in child theme functions.php or a plugin, so WordPress can process and execute them at the correct time.
-
Davidr
understood, thank you for the speed
- You must be logged in to reply to this topic.