Site logo

[Support request] Loop Template

Home Forums Support [Support request] Loop Template

Home Forums Support Loop Template

Viewing 8 posts - 16 through 23 (of 23 total)
  • Author
    Posts
  • #2542980
    David
    Staff
    Customer Support

    🙂 ok, if you can provide the login in the private info field we can take a look

    #2542992
    Benny

    Here we go

    #2543945
    David
    Staff
    Customer Support

    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.

    #2543995
    Benny

    It worked until i added the list-three class to the query grid 😀

    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!

    #2544232
    David
    Staff
    Customer Support

    Yeah it must be the code, if you can bear with me whilst i look into it 🙂

    #2545089
    David
    Staff
    Customer Support

    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 ?

    #2545330
    Benny

    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).

    #2546313
    David
    Staff
    Customer Support

    Glad to hear you found a solution.
    Ill take a look into how we can make this kind of easier to do!

Viewing 8 posts - 16 through 23 (of 23 total)
  • You must be logged in to reply to this topic.