Site logo

Archived topic

Loop Template

22 replies · Started by Benny on February 6, 2023

Viewing posts 1–15 of 23

Ist this doable with the loop template or do i have to to this with css afterwards?

Link to the picture --> https://ibb.co/TYQZrgW

For the greater "picture", i want the first 4 posts to be like this, then hook something in between and afterwards, there are normal posts that are older and behave "normal". I attached a picture to better explain what i want to do.

--> https://ibb.co/smJ8zfN

Hi there,

is this just for the Blog page or All Archive pages ?

All archives

To create a Loop template that has a separate hero loop and a main loop

Ok, its possible, but its quite complicated and theres currently a pagination bug that will be fixed in GB 1.7.

The steps would be:

1. Add new Loop template.
2. Add a Container for the hero, inside add 2 column grid.
3. In each column add a query loop -
3.1 first loop will be to show one posts and should have a class of list-one
3.2 second loop to show the the other column with the next 3 posts and should have a class of list-two
4. After this your static section.
5. Then your final loop to show the rest of the posts with a class of list-three

NOTES:
For All query loops: enable: Inherit the Query from Template DO NOT set any Parameters
The class should get added the Advacned > Additional CSS Class(es) of the Query Loop -> Grid Block

6. The display rules location should be set to ALL Archives.
7. Publish that

Now each of the posts lists needs it paging and offet params set. To do this you can use the generateblocks_query_loop_args filter hook - heres an example of that code:


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 ) {
                return array_merge( $query_args, array(
                    'offset' => 4,
                ) );
            }
        
    }

    return $query_args;
}, 10, 2 );

For the bug, the offets aren't getting applied to the Query Loops Pagination so it can lead to a mismatch when used.
Its being fixed in 1.7 which should be out mid february.
`

One thing i forgot to mention: The isnt exactly right. Do you have an idea why this is?

Nevermind, i duplicated blogposts and didnt change the time. Its working just fine. Thanks again.

OH wow, i am amazed - i wrote that on the fly and it worked :)

Glad to hear that!

One thing that does not seem to work is pagination. Any idea how to fix this?

Thank you!!

We just released GenerateBlocks 1.7 which fixes the Query Loops pagination "bug" so that filter should apply to pagination too.

Let me know

Did you add the Pagination block to the Query Loop block ? Its an option the query loop blocks toolbar.

I did, yes.

And silly question. I assume there is enough posts to trigger the need for pagination ?

Yes 😁

If you want to, i can send you credentials and you can have a look into it.

This archived topic is closed to new replies.