13th Mar '26
/
0 comments

Dynamic Remaining Posts Count for Load more Button in Bricks

A user asked in the Bricks Facebook group:

I have a loop of a CPT, showing 10 in a total of 16 posts and a load more button. I need the button text showing as “Load more 6 posts” (16-10). Is it possible with Bricks?

This Pro tutorial shows how a custom dynamic data tag, bl_remaining_posts can be registered that automatically calculates the number of posts not yet displayed in the query loop, both on initial page load and after the Load more button is clicked when using Load more functionality for Bricks' posts query loops.

The dynamic tag can then be used inline in the button text like this:

Load more ({bl_remaining_posts})

This also works when there are multiple query loops on a given page by specifying the Bricks ID of the element on which query loop is enabled.

{bl_remaining_posts:ELEMENT_ID}

Step 1

Install and active Bricks child theme if it's not already active.

This can be done at any stage - even if your WordPress site is already developed and live.

Step 2

Edit child theme's functions.php.

Below

wp_enqueue_style( 'bricks-child', get_stylesheet_uri(), ['bricks-frontend'], filemtime( get_stylesheet_directory() . '/style.css' ) );

add

wp_enqueue_script( 'bl-load-more-count', get_stylesheet_directory_uri() . '/js/load-more-count.js', array( 'bricks-scripts' ), filemtime( get_stylesheet_directory() . '/js/load-more-count.js' ), array( 'strategy' => 'defer' ) );

Step 3

Create a file named load-more-count.js in the js directory (it won't be present by default, create it) inside the child theme folder.

Add this code:

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
6 Random Posts from Tag A + 6 Random Posts from Tag B in a Single Bricks Query Loop

6 Random Posts from Tag A + 6 Random Posts from Tag B in a Single Bricks Query Loop

Displaying two set of random posts, inside one query loop.
Categories:
Pro
Upcoming Events in Bricks Grouped by ‘Month Year’ with Frontend Filtering by Event Type

Upcoming Events in Bricks Grouped by ‘Month Year’ with Frontend Filtering by Event Type

Updated version of the earlier Upcoming Events Grouped by ‘Month Year’ in Bricks tutorial with some improvements:
Pro
Categories and SubCategories Query Loop Tabs in Bricks

Categories and SubCategories Query Loop Tabs in Bricks

Learn how to show top-level parent categories as tab titles and the corresponding subcategories as tab contents using Bricks nested queries.
Categories:
Bricks Query Loop – Posts Authored by Logged in User

Bricks Query Loop – Posts Authored by Logged in User

How to display only the posts authored by the currently logged-in user in a query loop.
Categories:
Pro
Dynamic Posts Lightbox in Bricks using GLightbox

Dynamic Posts Lightbox in Bricks using GLightbox

Steps to set create a dynamic lightbox with content from the post inside of the query loop.
Categories:
Pro
Post Views Counter Query Loop in Bricks

Post Views Counter Query Loop in Bricks

How we can output the most viewed posts in your Bricks site in a query loop.
Categories: