Bricks Query Loop – How to Insert Elements After Every Nth Post

Update: Follow this tutorial instead.


This Pro tutorial provides the steps to output element(s) in a Bricks' query loop after every nth post.

Use case: Show an ad after every 3rd post.

This is based on the previous How to Insert Element(s) Between Query Loop Posts in Bricks tutorial.

It is possible to apply display: grid to the query loop element's parent if a grid layout is needed.

Note

This might break pagination. Implement this only for a non-paginated list of posts.

Step 1

Let's define a couple of custom functions for getting the loop index and the modulus of loop index.

Add the following in child theme's functions.php or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Instant access to 390+ Bricks code tutorials with BricksLabs Pro