[Resolved] Query loop and ensuring a single sticky post is being shown

Home Forums Support [Resolved] Query loop and ensuring a single sticky post is being shown

Home Forums Support Query loop and ensuring a single sticky post is being shown

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #2351279
    Joy

    Hi GP team,

    On our home page, I’ve added a query loop at the top of the page (based on the “image at left” query pattern block) and would like this to show a single sticky post (so whatever the most recently published post that has been designated as a sticky post). In the display settings, I’ve selected “items per page” as 1 and “max pages to show” as 1. I’ve published, cleared cache etc, but it’s still showing multiple sticky posts instead of just 1. I’ve tested this on a brand new page and it works fine so I’m not sure why it’s showing multiple posts on the home page.

    Would you be able to suggest anything to try here?

    Many thanks in advance!

    #2351282
    Fernando
    Customer Support

    Hi Joy,

    This issue will be addressed in the upcoming update. For now, can you try adding sticky-loop to the class list of the Grid Block inside the Query loop? Then, add this PHP:

    add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
        if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'sticky-loop' ) !== false ) {
            $query_args['ignore_sticky_posts'] = true;
        }
    
        return $query_args;
    }, 10, 2 );

    Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets

    The Alternative would be to download the current release candidate versions in https://generateblocks.com/account/

    #2351405
    Joy

    Many thanks Fernando – do you know roughly when the next update will be ready?

    #2351411
    Fernando
    Customer Support

    You’re welcome Joy! The upcoming update has already passed the alpha and beta testing, and is already in the Release Candidate category. It should be anytime soon.

    #2351415
    Joy

    Ok perfect, I think I’ll wait it out. Much appreciated!

    #2353534
    Fernando
    Customer Support

    You’re welcome Joy!

    #2373977
    Joy

    Hi again Fernando, hope all is well. I see the update came through which I’ve done but seem to be having the same problem. Is there something I’m doing wrong / could do to make this work properly? Thanks so much!

    #2373980
    Ying
    Staff
    Customer Support

    Hi Joy,

    You are using the WP query loop block, I think Fernando thought you were using the GenerateBlocks query loop block.

    And the update he mentioned is the GenerateBlocks plugin.

    Can you try that?
    https://docs.generateblocks.com/article/query-loop-overview/

    #2374082
    Joy

    Thanks Ying, apologies! I can’t seem to figure out how to get the GeneratesBlocks Query loop to work in the same way with the image on the left and the content title, date and excerpt on the right. Is there an article on how to do this? The query loop and grid seems to only allow 1 container per post and no option to format the text to the right of the image. Many thanks!

    #2374101
    Joy

    Hi again Ying, I think I’ve worked it out using columns and two separate query loops but please do let me know if you see any issues with this approach?

    #2374250
    David
    Staff
    Customer Support

    Hi there,

    using 2 query loops is perfectly fine way to do it.

    #2393525
    Joy

    Beauty! I’ll mark as resolved. thanks heaps

    #2393793
    David
    Staff
    Customer Support

    You’re welcome

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.