Query Loop - echo for each iteration

Using query to loop through posts to show a list of post titles.

For each list item, how do you output a number, starting from 0 and for each item it’s incremented by 1. i.e $count++;

{echo:count_post()} - {post_title}

It’s a very basic example, but would be extremely helpful to understand, as it could be applied to a lot of scenarios.

hi

  1. Using CSS counters - CSS: Cascading Style Sheets | MDN
  2. How to use ACF get_row_index() to echo repeater row index? - #2 by wplit
1 Like

Thank you WeLoveBricks. Appreciate the reply. get_loop_index() is the answer.

Is there documentation on all functions available for Bricks\Query:: or is it a matter of reading through the code?

Use case: return get_loop_index() in a function which can be echo in code block, basic text block or an attribute.

function countiteration() { return intval( Bricks\Query::get_loop_index() ) + 1; }

{echo:countiteration()}

3 Likes