Support

Account

Home Forums Add-ons Repeater Field Display Repeater Row Number (ie. 1 of 7)

Solved

Display Repeater Row Number (ie. 1 of 7)

  • Hello,

    I’m trying to display the row number of a repeater field, so it readers similar to a slide count (ie. 1 of 7 for row 1 of 7 rows). Thanks!

  • Would probably include something like this in your loop:

    
    <?php if( have_rows('repeater_field_name') ): ?>
      <?php 
      $slides = get_field('repeater_field_name'); 
      $total_slides = count($slides);
      $current_slide = 1;
      ?>
    
      <ul class="slides">
        <?php while( have_rows('repeater_field_name') ): the_row(); ?>
    
          <li class="slide">
            <?php $image = get_sub_field('image'); ?>
            <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
            <span class="count"><?php echo $current_slide++; ?> of <?php echo $total_slides; ?></span>
          </li>
    
        <?php endwhile; ?>
    
      </ul>
    <?php endif; ?>
    
  • This was solved by ACF Support. Here is the code if anyone is interested:

    <?php
    $rows = get_field('blog_style_gallery');
    $row_count = count($rows);
    $i=1;
    ?>
    
    <?php
    echo "Slide: ". $i." of ".$row_count." Rows";
    $i++;
    ?>
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Display Repeater Row Number (ie. 1 of 7)’ is closed to new replies.