Published on Sep 21, 2021

Loop Counter for Repeaters in Oxygen

Sridhar Katakam

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:

  1. The loop counter numbers other than the first one can be seen on the front end.
  2. This works independently per Repeater.
tagschevron-leftchevron-rightchainangle-rightangle-upangle-downfolder-ocalendar-check-omagnifiercrossmenuchevron-downarrow-right