1

I am using the wordpress plugin repeater. I would like each sub_field post, which in this case starts from the LI, to have its own item counter.

So the first item would have a class of one, the second a class of two and so on.

<?php while( has_sub_field('home_panels') ): ?>
<li class="item" data-factor="1">
    <a href="<?php the_sub_field('panel_link'); ?>">
    <img src="<?php the_sub_field('panel_image'); ?>" />
    <div class="caption">
        <div>
            <div>
            <h3><?php the_sub_field('panel_title'); ?></h3>
            <span class="excerpt"><?php the_sub_field('panel_description'); ?></span>
            </div>
        </div>
    </div>
    </a>
</li>
<?php endwhile; ?>
RNK
  • 5,582
  • 11
  • 65
  • 133
probablybest
  • 1,403
  • 2
  • 24
  • 47

1 Answers1

1
<?php $i = 0; while( has_sub_field('home_panels') ): $i++; ?>
    <li class="item item-<?php echo $i; ?>" data-factor="1">

A CSS class can't begin with a number, so name your counter something like item-1, item-2, etc.

mopo922
  • 6,293
  • 3
  • 28
  • 31