Loop Logic

Loop Logic adds two template tags you can write in a snippet’s HTML tab:

  • <If> — show a block only when an attribute matches a condition (with optional <ElseIf> /
    <Else>).
  • <Loop> — repeat a block for each row of a Repeater attribute, or over taxonomy terms or a
    posts query.

It works only when the “Enable Loop Logic” tool is on (Tools → Site Tools). The attributes you
reference are defined on the snippet’s Attributes tab. In the HTML editor, the Loop Logic
button opens a reference dialog and inserts ready-made examples.

Loop Logic supports nesting to any depth — <Loop> inside <Loop>, <If> inside <If>, and <If>
inside <Loop> all work.


<If> — conditional blocks

Show the inner content only when the condition is true.

<If field="attr_name" value="expected_value">
  <!-- shown when the condition is true -->
</If>

<If field="attr_name" value="expected_value" operator="!=">
  <!-- shown when NOT equal -->
</If>

<If field="attr_name" value="" operator="not_empty">
  {{$attr_name}}
</If>
  • field — the attribute name to test.
  • value — the value to compare against (may be empty for empty / not_empty).
  • operator — optional; defaults to = (equals).

Operators

Operator Aliases Comparison
= ==, equals Equals (default)
!= not, not_equals Not equals
> greater Greater than (numeric)
>= greater_equals Greater or equal (numeric)
< less Less than (numeric)
<= less_equals Less or equal (numeric)
contains Contains the text
not_contains Does not contain the text
starts_with Starts with the text
ends_with Ends with the text
empty Value is empty
not_empty Value is not empty
in In a comma-separated list (value="a,b,c")
not_in Not in a comma-separated list
true Value is truthy (1/true/yes/on)
false Value is falsy

<ElseIf> / <Else> branches

An <If> block can contain <ElseIf …> branches and a final <Else> (these are separators — no
closing tags). The first matching branch is shown; if none match, <Else> is used:

<If field="plan" value="pro">
  Pro features
<ElseIf field="plan" value="trial">
  Trial features
<Else>
  Upgrade now
</If>

<Loop> — repeater loops

Repeat the inner template once per row of a Repeater attribute. Field names must match the
sub-fields defined for that repeater in the Attributes tab.

<Loop field="my_repeater">
  <div>{{loop.title}}</div>
  <div>{{loop.description}}</div>
</Loop>

Placeholders inside a loop

Placeholder Description
{{loop.field_name}} Value of a sub-field in the current row
{{field_name}} Short alias — same as above
{{loop.index}} Current row number, starting at 1
{{loop.index0}} Current row number, starting at 0
{{loop.is_first}} true on the first row
{{loop.is_last}} true on the last row

<If> inside a <Loop>

Conditions inside a loop are checked per row, against that row’s fields and the loop meta:

<Loop field="items">
  <div class="item">
    <h3>{{loop.title}}</h3>
    <If field="status" value="active">
      <span class="badge">Active</span>
    </If>
    <If field="loop.is_first" value="true"><hr></If>
  </div>
</Loop>

Nested loops

A <Loop> can contain another <Loop>:

<Loop field="groups">
  <h3>{{name}}</h3>
  <ul>
    <Loop field="items">
      <li>{{loop.title}}</li>
    </Loop>
  </ul>
</Loop>

<Loop> over terms / posts

A loop can also pull live WordPress data with a source attribute. The same {{loop.field}}
placeholders and per-row <If> apply.

source="terms" — taxonomy terms

<Loop source="terms" taxonomy="category" hide_empty="true" orderby="name" order="ASC" number="10">
  <a href="{{loop.link}}">{{loop.name}} ({{loop.count}})</a>
</Loop>

Attributes: taxonomy (default category), hide_empty (default true), number, orderby,
order, parent. Row fields: id, name, slug, link, description, count.

source="posts" — posts query

<Loop source="posts" post_type="post" posts_per_page="5" orderby="date" order="DESC">
  <a href="{{loop.link}}">{{loop.title}}</a>
  <div>{{loop.thumbnail_html}}</div>
</Loop>

Attributes: post_type (default post), posts_per_page (default 5), orderby, order,
category (term ID), or taxonomy + term. Row fields: id, title, link, excerpt, date,
thumbnail (URL), thumbnail_html (<img> tag).

⚠ These run a live query on every page render and are checked per request, so behind full-page
caching the cached page is served without re-querying.


Notes

  • ⚠ Nothing is processed unless Enable Loop Logic is on.
  • An unbalanced tag (a missing </If> or </Loop>) is shown as plain text rather than breaking the
    rest of your markup.
  • A loop over a missing/empty repeater (or an empty query) outputs nothing.