Archived topic
Loop Template
22 replies · Started by Benny on February 6, 2023
:) ok, if you can provide the login in the private info field we can take a look
Here we go
What happens if you remove the current Query Loop in your loop template, and add a new query loop ?
You may want to Quick Edit and set the status to Draft for the current element and make a new one to test.
Just wondering if its holding onto the legacy code.
It worked until i added the list-three class to the query grid :D
It works with my query loop IF i remove the list-three class. So maybe something isnt quite right. If you want to look into it, you have my credentials. And again, thank you for your great work. I appreciate it alot!
Yeah it must be the code, if you can bear with me whilst i look into it :)
OK, so now i find out that using offset breaks pagination when inheriting the query.
Which can be a bit of a pain, as it means creating our own offset param when the page is paged, which can lead to some weird side effects.
But i tested this on a local dev site, and it looks to be working:
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
// Check your logic to apply the filtering only to specific loop
if (
!empty( $attributes['className'] )
&& ! is_admin()
) {
// list-one set pages to 1 and offset by 0
if ( strpos( $attributes['className'], 'list-one' ) !== false ) {
return array_merge( $query_args, array(
'posts_per_page' => 1,
'offset' => 0,
) );
}
// list-two set pages to 3 and offset by 1
elseif ( strpos( $attributes['className'], 'list-two' ) !== false ) {
return array_merge( $query_args, array(
'posts_per_page' => 3,
'offset' => 1,
) );
}
// list-three offset by 5
elseif ( strpos( $attributes['className'], 'list-three' ) !== false ) {
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$posts_per_page = 6; // Set the posts per page here
$offset = ($paged - 1) * $posts_per_page + 3; // 3 is the offset value
return array_merge( $query_args, array(
'posts_per_page' => $posts_per_page,
'offset' => $offset,
) );
}
}
return $query_args;
}, 10, 2 );
Note that you have to define the posts_per_page in the code.
Do you want to give that a try ?
Works like charm. Do you have a clue how to get rid of the empty fourth category page? (Fixed this with Settings > Reading > Blog pages show at most = 13).
Glad to hear you found a solution.
Ill take a look into how we can make this kind of easier to do!