Home Forums Add-ons Repeater Field Count Repeater Items Reply To: Count Repeater Items

  • Is there any way to count the items in a repeater but to use that value before the while loop?

    I am using it with foundation block grid and want to set the number of columns to the number of repeater items instead of hardcoding it:

        // REPEATER NAME
     	  if( have_rows('grid') ): 
     	  <div class="grid-x grid-margin-x small-up-1 medium-up-3 large-up-3"  data-equalizer>
        <?php // REPEATER ROW NAME
        while ( have_rows('grid') ) : the_row();  ?>
        <!-- BLOCK GRID  -->  
            $grid_image = get_sub_field('grid_image'); 
            $caption_header = get_sub_field('caption_header'); 
            $caption_content = get_sub_field('caption_content');
             $small_size = 'square-small';
             $medium_size = 'square-medium';         
            $small = $grid_image['sizes'][$small_size];
            $medium = $grid_image['sizes'][$medium_size];
              <div class="cell">
               <h5  data-equalizer-watch><?php echo $caption_header; ?></h5> 
        	     <img data-interchange="[<?php echo $small; ?>, small], [<?php echo $medium; ?>, medium], [<?php echo $medium; ?>, large], [<?php echo $medium; ?>, xlarge]" alt="<?php echo $grid_image['alt'] ?>" />
        	       <?php echo $caption_content; ?>      
             endwhile; ?>
            <?php endif;   ?>