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:
<?php
// 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 -->
<?php
$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; ?>
</div>
<?php
endwhile; ?>
</div>
<?php endif; ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.