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..

How to create filters with IsotopeJS in Bricks (Part 3): apply multiple filters

How to create filters with IsotopeJS in Bricks (Part 3): apply multiple filters

This tutorial will review how to apply multiple filters to an isotope container using the IsotopeJS library‘s features in Bricks.
Displaying SureCart Featured Products & Products Collections with a Query Loop

Displaying SureCart Featured Products & Products Collections with a Query Loop

We walk through how to use a query loop to display SureCart products, featured products & collections.
Categories:
How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 2)

How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 2)

This tutorial provides the PHP & JS codes that can be pasted in order to create a flying effect on map markers each time your…
Pro
Excluding Duplicate Posts from Query Loops in Bricks

Excluding Duplicate Posts from Query Loops in Bricks

How to ensure that posts are not duplicated when two query loops are used on the same page.
Categories:
Pro
Nested Queries in Bricks – Posts Grouped by Published Years and Categories

Nested Queries in Bricks – Posts Grouped by Published Years and Categories

In the past we showed how posts could be grouped by years in Bricks. This Pro tutorial takes it further by grouping posts by categories…
Categories:
Pro
Nested Meta Box Query Loop Inside a CPT Query Loop in Bricks

Nested Meta Box Query Loop Inside a CPT Query Loop in Bricks

This Pro tutorial provides the steps for setting up a cloneable Meta Box group query inside a CPT query in Bricks. Scenario: CPT: course Meta…
Categories:
Pro
Alternating Posts from Two Post Types in Bricks

Alternating Posts from Two Post Types in Bricks

How to output posts from two seperate post types, alternating in a query loop.
Categories:
Latest Featured Posts First in Bricks Query Loop (No Duplicates)

Latest Featured Posts First in Bricks Query Loop (No Duplicates)

In the Bricks Facebook group a user asks: We can use AI to help unfreeze our brains sometimes or at least have it write the…
Categories: