-
AbsaWeb
Hi,
We start from this topic:
https://generate.support/topic/pagination-with-multiple-query-loop-blocks/#post-62219
As this user says:
3. Add a Block Element Content Template
Here you will design the content template for default theme loop.It does not work correctly. The same happens to me.
Each block doubles for the number of entries that I have defined in my WP.
It works well that only page hero appears on page 1, but the loop does not and the user of that topic did not find a solution either.
I will send you the data privately.
Thank you.
-
AbsaWeb
If I put it as a Loop Template, the layout and the posts to be displayed are correct, but the pagination is with a query, when in reality there is page/2/ …etc.
Please, any help?
Thank you.
-
AbsaWeb
In my functions I have the code that David indicated in the aforementioned topic.
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) { $block_class = 'hero-query'; if ( // if the query loop grid has $block_class ! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], $block_class ) !== false ) { $query_args = array_merge( $query_args, array( 'posts_per_page' => 1, 'offset' => 0, )); } return $query_args; }, 10, 2 ); add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) { $block_class = 'hero-query2'; if ( // if the query loop grid has $block_class ! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], $block_class ) !== false ) { $query_args = array_merge( $query_args, array( 'posts_per_page' => 2, 'offset' => 1, )); } return $query_args; }, 10, 2 ); add_filter( 'generate_block_element_display', function( $display, $element_id ) { if ( 381514 === $element_id && is_paged() ) { $display = false; } return $display; }, 10, 2 ); //Offset category archive posts add_action('pre_get_posts', 'myprefix_query_offset', 1 ); function myprefix_query_offset(&$query) { // Before anything else, make sure this is the right query and not in the admin side. if ( ! is_admin() && $query->is_main_query() ) { //First, define your desired offset... $offset = 3; //Next, determine how many posts per page you want (we'll use WordPress's settings) $ppp = get_option('posts_per_page'); //Next, detect and handle pagination... if ( get_query_var('paged') ) { //Manually determine page query offset (offset + current page (minus one) x posts per page) $page_offset = $offset + ( (get_query_var('paged')-1) * $ppp ); //Apply adjust page offset $query->set('offset', $page_offset ); } else { //This is the first page. Just use the offset... $query->set('offset',$offset); } } } add_filter('found_posts', 'myprefix_adjust_offset_pagination', 1, 2 ); function myprefix_adjust_offset_pagination($found_posts, $query) { //Define our offset again... $offset = 2; //Ensure we're modifying the right query object... if ( ! is_admin() && $query->is_main_query() ) { //Reduce WordPress's found_posts count by the offset... return $found_posts - $offset; } return $found_posts; }
-
Fernando
Hi there,
To clarify, when you created a Content Template, did you add a Query Loop Block inside?
When you use a Content Template, there shouldn’t be a Query Loop inside.
For instance, the video here shows how to create one: https://docs.generatepress.com/article/block-element-content-template/
-
AbsaWeb
Hi,
I think you haven’t understood me, or maybe I haven’t explained myself.
If you look at this topic and see David’s answers, I think you will understand what I mean.
David said: “3. Add a Block Element Content Template
Here you will design the content template for default theme loop.Set the Display Rules Location to Blog”
https://generate.support/topic/pagination-with-multiple-query-loop-blocks/#post-62219
Thanks.
-
Fernando
I’m not sure I understand what you mean.
David mentions “Add a Block Element – Content Template“. You created a Block Element – Loop Template. Is there a reason why you’re opting for a Loop Template?
-
AbsaWeb
No, no, the name I gave it is Loop Template, but it is a Block Element – Content Template.
Please, if you enter with the information that I have given you, you will see that it is the type that I indicated. -
Fernando
I see.
But you added a Query Loop inside your Content Template. There shouldn’t be a Query Loop inside a Content Template. It would result in a loop within a loop which causes the duplicate.
The video here shows how to create a Content Template properly: https://docs.generatepress.com/article/block-element-content-template/
-
AbsaWeb
Hello again,
I have changed and removed the loop, but doing it that way makes no sense to the functions offset.
If you can look at it it would be of great help to me.
Thank you.
-
Fernando
This part in the code defines the offset for the Content Template:
add_action('pre_get_posts', 'myprefix_query_offset', 1 ); function myprefix_query_offset(&$query) { // Before anything else, make sure this is the right query and not in the admin side. if ( ! is_admin() && $query->is_main_query() ) { //First, define your desired offset... $offset = 3; //Next, determine how many posts per page you want (we'll use WordPress's settings) $ppp = get_option('posts_per_page'); //Next, detect and handle pagination... if ( get_query_var('paged') ) { //Manually determine page query offset (offset + current page (minus one) x posts per page) $page_offset = $offset + ( (get_query_var('paged')-1) * $ppp ); //Apply adjust page offset $query->set('offset', $page_offset ); } else { //This is the first page. Just use the offset... $query->set('offset',$offset); } } } add_filter('found_posts', 'myprefix_adjust_offset_pagination', 1, 2 ); function myprefix_adjust_offset_pagination($found_posts, $query) { //Define our offset again... $offset = 2; //Ensure we're modifying the right query object... if ( ! is_admin() && $query->is_main_query() ) { //Reduce WordPress's found_posts count by the offset... return $found_posts - $offset; } return $found_posts; }
Try altering the offset value in this code.
-
AbsaWeb
The offset are to 3, but nothing.
Also they keep duplicating me and if you can tell me how to remove the title…
Thanks.
-
Fernando
Can you recreate the Content Template? The Content Template you have is still using Blocks created along with the Query Loop.
That’s causing the issue.
-
AbsaWeb
Ok, right. I’ll try, but could you tell me how to remove the title?
Thank you.
-
Fernando
In your Block Element – Page Hero Element settings, there should be an option to remove the Title. Reference: https://docs.generatepress.com/article/block-element-page-hero/#disable-title
Can you toggle that?
-
AbsaWeb
HI,
The title thing is solved, but I still have problems displaying the grid block since it doesn’t respect the styles.
I have created global style but nothing.
Please could you help me, I don’t know what to change or try anymore.
Thank you.
-
Hi there,
why do you have the Grid Block in your Content Template ?
If you built that loyout without the grid block then it would fill the blog columns
- You must be logged in to reply to this topic.