How to Insert Element(s) Between Query Loop Posts in Bricks

Update on 16 Aug 2023: Follow this tutorial instead.


This Pro tutorial shows how we can insert a Div (or any custom HTML) after nth post (Ex.: after 5th post) in the list of posts output via a query loop in Bricks.

This can be used to insert an ad/banner or any other functionality like Top Posts in between posts.

Step 1

Define a custom function that returns the current index in the query loop.

Add the following in child theme's functions.php (w/o the opening PHP tag) or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 526 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Using WP Grid Builder Facets with Bricks’ Query Loop

Using WP Grid Builder Facets with Bricks’ Query Loop

Update: This tutorial was written before WPGB had a Bricks add-on. Now, it is advisable to use that add-on instead. Get it from here. Updated…
Categories:
Pro
Custom Dynamic Data Tags in Bricks

Custom Dynamic Data Tags in Bricks

Update on 16 Aug 2023: Follow this tutorial instead. This Pro tutorial shows how we can insert a Div (or any custom HTML) after nth…
Pro
Check If The Latest Post Was Published in The Last X Minutes

Check If The Latest Post Was Published in The Last X Minutes

In this Pro tutorial we shall define a custom function that takes in the number of minutes as an argument and returns true if there…
Categories:
Pro
At Least 1 Search Result Condition in Bricks

At Least 1 Search Result Condition in Bricks

Registering a custom condition to render elements depending on whether there is at least one search result.
Categories:
Month-based Background Image in Bricks

Month-based Background Image in Bricks

How to have different background images for an element for different quarters in a year.
Categories:
Pro
Nav Menus Custom Query Types in Bricks

Nav Menus Custom Query Types in Bricks

Updated on 21 Aug 2024 This Pro tutorial shows how custom query types for each navigation menu can be generated in Bricks. This enables us…