This tutorial shows how we can obtain the index of each post output by Oxygen‘s Repeater component, thanks to Rick and Taylor Drayson from the Oxygen Discord chat.
In the Repeater’s Div, add a Code Block having:
<?php
// Ensure the global $oxy_vsb_use_query variable is in scope
global $oxy_vsb_use_query;
$index = $oxy_vsb_use_query->current_post + 1;
echo $index;
?>
Sample use
If you want to target say, every 2nd post:
<?php
// Ensure the global $oxy_vsb_use_query variable is in scope
global $oxy_vsb_use_query;
$index = $oxy_vsb_use_query->current_post + 1;
echo $index;
if ( 0 === $index % 2 ) {
echo ' - every second post';
}
?>
Note:
- The loop counter numbers other than the first one can be seen on the front end.
- This works independently per Repeater.