• Resolved curiousjake

    (@curiousjake)


    Hi,

    The Query Loop block is fantastic – super intuitive and a great addition to GB. I’ve been digging to see if there is a way to output some default content if the Query Loop returns no posts, but it doesn’t look like there is even a filter on the returned content so the block is just empty if no posts are returned. Is this true? If so, can I suggest you add a filter here so we can display some default output? ??

    Thanks!

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Support ying

    (@yingscarlett)

    Hi there,

    In that case, what kind of content do you want to output?

    Let me know!

    Thread Starter curiousjake

    (@curiousjake)

    Hi Ying,

    Perhaps some raw HTML? Or a backup post template block for when there are no posts? But even just some text saying ‘No posts found’ would be fine.

    Thanks,

    Plugin Support David

    (@diggeddy)

    Hi there,

    for now you can do something like this:

    1. Add this CSS to your site:

    .has-no-post-message:not(:empty) + .no-post-message {
    	display: none;
    }

    2. Select your Query Loop block, and give it an Advanced > Additional CSS Class(es) of: has-no-post-message

    3. Then immediately after the Query Loop Block, add a new block eg. a Container and give it a Class of no-post-message

    3.1 Add whatever you want in the no-post-message container. It will only display if the query loop before it empty.

    George

    (@quantum_leap)

    @diggeddy Thanks, that was helpful!

    @diggeddy, I don’t see the GenerateBlocks Query Loop block having an Advanced > Additional CSS field. I’m using GenerateBlocks 1.6.0 and GenerateBlocks Pro 1.4.0.

    Plugin Support fernandoazarcon2

    (@fernandoazarcon2)

    Hi @theframeguy,

    Try adding the Query Loop inside a GB Container, then give this Container the has-no-post-message class.

    Then, add the no-post-message after the Grid Block of the Query Loop Block.

    Example: https://share.getcloudapp.com/6quN5v6J

    The code for this would be:

    .has-no-post-message .gb-query-loop-wrapper:not(:empty) + .no-post-message {
    	display: none;
    }

    Thank you @fernandoazarcon2, that works. Of course, making a message field part of the GB Query Loop block would be the best solution. While working in the editor, the GB Query Loop block does display “No results found” when there are no posts.

    Plugin Support fernandoazarcon2

    (@fernandoazarcon2)

    You’re welcome, @theframeguy!

    Plugin Support fernandoazarcon2

    (@fernandoazarcon2)

    Hi there! We haven’t heard back from you for a while now so we’re going to go ahead and set this topic as resolved. Feel free to reply if you need any more help.

    Hi, since the Query Loop may output some whitespaces, :empty will not work. Is there another way to introduce content here?

    I have noticed that there is a core/query-no-results block. this does the trick ??

    Just add it inside your loop and add content there.

    • This reply was modified 1 year, 7 months ago by bellian.
    Plugin Support fernandoazarcon2

    (@fernandoazarcon2)

    Glad you found a solution!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Query Loop Block – Default output when no posts’ is closed to new replies.