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.

Restricting Display to Queried Loop Category to Be Used in GP Query Loop: Seekin

  • I’m utilizing the GP Query Loop to display product listing categories. In this loop, I want to restrict the display to only the category that is specifically queried, rather than all related categories. I’m using a Heading block to dynamically display the category, but it currently shows all categories associated with the product. Is there a hook, filter, or block setting that can be applied to ensure only the queried category is displayed within the loop?

    https://postimg.cc/gallery/q4NpSyf

  • Hi there,

    In that case, set the headline’s dynamic content source to title instead of list of terms.

  • Hi Ying, thanks for responding and for your prompt response.

    When I set it to the title the product title or name loads, and I have another dynamic data inside the query loop block set to the title which loads the product name or title correctly.

    I am required to load the single category that I used to query the query loop block. To do this I’m setting the headline’s dynamic content source to a list of terms >> product categories. But this loads all categories.

  • Hi there,

    I just dug through the code here and it doesn’t look like the queried category name is available inside the dynamic Headline. I’ll see if we can do something about that.

    Is it necessary to display the single category name if the query itself is set to only display posts in that category? Seems like a somewhat unnecessary part of the loop, as the category being displayed can be mentioned in the title of the page etc…

    Let me know 🙂

  • Hi Tom!

    Thanks for reviewing the code! I understand that the category name might not be crucial within the loop.

    However, including it helps provide a clearer context for users, especially those landing directly on the page.

    I’d appreciate solutions or alternatives that can achieve a similar effect.

    Thanks!

  • From an HTML rendering perspective, this isn’t possible as the content inside doesn’t have access to the value you’re looking for.

    A “hacky” was to do this is through CSS, and requires some manual setup.

    1. Add a Headline block inside of your Query Loop where you want the category name to show up. You can leave it blank so there’s no content.
    2. Give this empty Headline block a class in the “Advanced” panel. For example: category-name
    3. In the Grid block (directly under the Query Loop block), give it a class in the Advanced panel that specifies which Query Loop this is. For example, if I’m querying a “books” term, I could do this as my class name: query-books
    4. Now, we can add the following CSS:

    .query-books .category-name:after {
        content: "Books";
    }

    This is the only way I can think of doing it at the moment, unfortunately.

    Hope this helps!

  • Tom, hacky was helpy, thanks to you.

    However, it’s not clickable though. Is there a way you think can make the content: “Books”; clickable (add a link)?

  • It’s not possible, unfortunately.

  • Thanks, Tom and Ying. I really appreciate your support!

  • You are welcome   🙂

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