23rd Jun '23
/
0 comments

Query Loop Index in Bricks

This Pro tutorial provides the code for getting the index of each post in Bricks' query loops.

This can be used for either outputting the post number (screenshot below) or for checking for nth post and conditionally outputting elements (Ex.: How to Insert Element(s) Between Query Loop Posts in Bricks).

Note: If you have BricksExtras installed, there is no need to use the below custom function. BricksExtras comes with it. Check the Dynamic Tags doc page.

Step 1

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

Get access to all 610 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Related Episodes Grouped by Episode Chapters on Single Podcasts in Bricks when using JetEngine

Related Episodes Grouped by Episode Chapters on Single Podcasts in Bricks when using JetEngine

A user asks: How to Display Related Episodes Grouped by Chapters on a Podcast Page in Bricks? Hi everyone, I have two post types created…
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
How to Insert an Ad or an Element Between Posts in Bricks

How to Insert an Ad or an Element Between Posts in Bricks

How to insert an image or any Bricks element between posts output by a query loop.
Categories:
Tags:
Pro
Parent post Bricks query loop

Parent post Bricks query loop

Updated on 5 Feb 2024 In the BricksLabs Facebook group a user asks: Is there a way to output the data of a parent post…
Categories: