display class for number of posts with sub_fields

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; ?>

Related posts

Leave a Reply

1 comment

  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.