Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

CPT Archive Page Issue Using GB Query Loop

  • driftcreative

    Hi, I use a single query loop element set to ‘inherit query from template’ to handle various property CPT tax archive pages, and each archive type has a separate hero element with a static background image included.

    The ‘special offers’ page uses this template, but I’m happy to create a separate query loop if needed, once you understand the problems below.

    (1) When the query loop returns empty, the hero background image does not appear, even though this is a static image set within the hero element – it’s not a dynamically set post image.

    (2) The empty query loop leaves various empty containers from my element, which I need to hide if they are empty. You can see these take up vertical white space between the blue wave and the “Get 15% off” text which is pushed down the page.

    (3) Specifically for the special offers archive, if there are currently no special offer properties, I want to be able to display a specific content block (and hide this when there are properties listed).

    Thanks!
    David

  • Hi there,

    1. May I have a look at the backend? As it looks like no image is chosen inspecting the front end.

    2. try this CSS:

    .gb-container-cont-outer:has(.gb-query-loop-wrapper:empty) {
        display: none;
    }

    3. Yes, we can do so with CSS. Let me know which section you are referring to.

  • driftcreative

    Hi Ying, thanks for the reply. Login details added… Thanks!

  • it’s not a static image; you’ve enabled the dynamic background image for the container:
    https://app.screencast.com/7iEiIg21XjlUU

    As for point 3, can you point me to the section you are referring to?

  • Ah, thanks Ying. OK for point 3, please see this screen grab:

    https://postimg.cc/qzVtW4gg

    Thanks!

  • 1. Add a class to the root container of the loop template, eg. the-loop.

    2. Add a class to the root container of the section in question, eg. show-with-empty-loop

    2. Add this CSS:

    body:not(.wp-admin) .the-loop:has(.gb-query-loop-wrapper:empty) ~ .show-with-empty-loop {
        display: block;
    }
    
    body:not(.wp-admin) .show-with-empty-loop {
        display: none;
    }

    Let me know if this helps!

  • driftcreative

    Hi Ying,

    Getting there, thanks! 🙂 Just a couple of issues now:

    (1) The code for point 3 is also hiding the content block in the admin area (Elements edit page) as I use the same stylesheet for front and back end. Is there a way to adjust this CSS to ignore ‘when in admin’?

    (2) Just jumping back to the hero image issue. The image pulls from an ACF image field in the term meta and I cannot seem to get this to display when the archve is empty. I tried toggling on ‘use fallback image’ in the hope that it would pull through the hard-coded image in the element itself, but no luck. This is a stumbling block at the minute.

    Thanks!
    David

  • 1. yes, I adjusted the CSS, please check.https://generate.support/topic/cpt-archive-page-issue-using-gb-query-loop/#post-156527

    2. I feel like your site is heavily cached; it’s really hard to debug or do any testing. can you disable your cache plugin and server cache if you have one? Once that’s done, we can do some more testing.

  • Hi Ying, the LiteSpeed cache has been disabled. Thanks!

  • It looks like a bug in V1 block. any chance you can update your GB and GB Pro to 2.0.1 and 2.0.0?
    And use v2 blocks to create the section?

    You will need to switch off v1 at generateblocks > settings, however, this is a one-way ticket, and once it’s off, you can not turn it back to v1. So think about it.

    Otherwise, we can write some CSS to get the background image.

    body.archive.tax-property-status.term-special-offers:has(.gb-grid-wrapper.gb-query-loop-wrapper.gb-grid-wrapper-single-prop-listing-query-grid:empty) .gb-container-hero-brand-bg-img:before {
        background-image: url(https://www.your-domain.co.uk/wp-content/uploads/sample-img.jpg);
    }
  • Thanks Ying, I think I’ll give the CSS option a go first. The GB update is on the cards, but I need to set up a local copy and test first. Thanks! David

  • You are welcome   🙂

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