Modules / Query loops & dynamic data

Query loop: alternate template every N items

Render every N-th item of a query loop with a Bricks template instead of the normal card. Use it for promo cards, ads or featured tiles inside a post grid.

#11 of 39 modules by votes

  • On by default
  • Needs Bricks 2.4 or newer
  • Tested with Bricks 2.4.3

Tile 11 of 39, ranked by votes · Recording in progress

Where to find it in the builder

Container, Block, Div, Content tab, directly under the Query control. The fields show only while the element has a query loop.

How to use it

  1. Build the replacement card as a Bricks template. Its type must be Section or Content, and it must be published.
  2. Select the Container, Block or Div that has the query loop.
  3. Under the Query control, set Alternate template every N items. With 3, the 3rd, 6th and 9th item use the template.
  4. In Alternate template, pick your template. The list is searchable.

How it works with your loop

  • The template renders with the loop item as the current post. Dynamic data inside the template, such as the post title, reads that item.
  • The swapped item replaces the normal card completely. Kiln wraps it in a div with display: contents that carries the loop element's brxe- class and a kiln-alt-item class. Bricks needs that class to clear old results when a filter or AJAX pagination refreshes the loop.
  • The count starts after your loop's offset. With an offset of 2 and N set to 3, the 3rd card you see is the first swapped one.
  • The count continues across load-more pages.
  • On a site with WPML, Kiln uses the translation of the template that matches the page language.

Limits

  • The builder shows your normal cards. Kiln swaps the template on the front end only.
  • Both fields need a value. Leave either empty and the loop renders as usual.
  • A template that is not published, or is not a Section or Content template, is ignored.
  • Do not use it on a loop inside a Nav element. The swapped item does not keep the list-item wrapper.

Settings

None. Turn the module on in Bricks > Kiln (it is on by default).

Requirements

Bricks 2.4 or newer.