mizzinc
1
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.
mizzinc
3
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?
mizzinc
4
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