15th Mar '26
/
0 comments

Per-Category Load More with Post Count in Bricks Builder Nested Query Loops

In the BricksLabs group, a user asks:

Hi everyone!

I'm working on a website where I need to list a large number of products on the product archive page, which would slow down the website.

Currently, the page structure works as follows: there is a query that lists the product categories ("Telefonok", "Tabletek", etc.), and within that there is another query that lists the products of the given category.

My idea was to display 4-5 products per category, and when the user clicks the "Load More" button, additional products would appear (it would also be fine if, when the user clicks "Load More" within a given category, it triggers infinite scroll so that products load automatically on scroll — but only within that specific category).

My main problem is that since the product categories are also dynamic (they come from a query), I can't choose a unique CSS selector for the AJAX-based loading, so the infinite loader doesn't work either.

Please advise on how this problem can be overcome. Thank you!

This Pro tutorial provides the steps to make Load more buttons below posts under categories work in Bricks when using nested query loops.

Bricks Builder's native Load more interaction breaks down in nested query loops. For example, when posts are grouped inside a taxonomy loop, every category shares the same query instance key, so clicking any Load more button loads posts for the wrong category or affects all groups at once.

This tutorial walks through a complete solution using a Bricks Component to encapsulate the per-group markup, a custom JavaScript file that reads Bricks' internal query trail elements before they are removed from the DOM, and a custom PHP dynamic data tag {bl_remaining_posts} that reports how many posts remain per group on initial page load.

Our solution also covers keeping the remaining count in sync after each AJAX load, wiring up Bricks' built-in AJAX loader animations so the correct spinner appears inside the active group only, and hiding buttons once all posts for a given term are loaded.

Step 1

Edit your Page/Template with Bricks, copy the fully-built Section's JSON from our site and paste.

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 633 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Posts Grouped by Month and Year in Bricks

Posts Grouped by Month and Year in Bricks

Nesting query loops with months & years in descending order, with the inner loop outputting the posts.
Categories:
Pro
Custom Nested Queries in Bricks

Custom Nested Queries in Bricks

In most of the previous tutorials covering nested query loops in Bricks on this site, we accessed the parent query's looping object in the inner…
Categories:
Pro
Bricks Query Loop for Top-level Parent Pages with Children

Bricks Query Loop for Top-level Parent Pages with Children

In the Bricks Facebook group, a user asked: Looking for a custom query to output a list of posts in the same hierarchy that the…
Categories:
Pro
Hierarchical Posts with Nested Query Loops in Bricks

Hierarchical Posts with Nested Query Loops in Bricks

Learn how to set up nested query loops in Bricks to show hierarchical posts with child posts grouped under their corresponding parent posts
Categories:
Pro
Events grouped by Event Date custom field in Bricks

Events grouped by Event Date custom field in Bricks

This Pro tutorial for Bricks users provides the steps to output posts of an event custom post type dynamically grouped by the value of their…
Categories:
Pro
Posts Grouped by Post Dates in Bricks

Posts Grouped by Post Dates in Bricks

Setting up query loops for “Post Dates” with an the inner loop displaying all posts published on that day.
Categories: