Home › Forums › ACF PRO › Repeater Field Wrapper, Incrementing Class and IDs › Reply To: Repeater Field Wrapper, Incrementing Class and IDs
Hi @ericcarroll and @stinkykong
I’m honestly not sure what you’re trying to achieve here.. your descriptions are a bit confusing to be honest 🙂
But here’s what I think you’re saying.. You want to show the content within the each repeater.. you want to first check wether some content exists to avoid empty html wrapping elements. You want to increment the “id” of the gallery content for each gallery listed.
Here’s some sample code based on your own.
<?php $i = 0; ?> <?php if( have_rows('manufacturing_grid_blocks') ): while ( have_rows('manufacturing_grid_blocks') ) : the_row(); ?> <div class="small-12 medium-4 large-4 columns grid-block"> <?php if( get_sub_field('manufacturing_grid_media') ): ?> <img src="<?php the_sub_field('manufacturing_grid_photo'); ?>" /> <?php endif; ?> <?php the_sub_field('manufacturing_grid_video'); ?> <h3><?php the_sub_field('manufacturing_grid_header'); ?> <span><?php the_sub_field('manufacturing_grid_sub_header'); ?></span></h3> <?php if( get_sub_field('manufacturing_grid_content') ): ?> <p><?php the_sub_field('manufacturing_grid_content'); ?></p> <?php endif; ?> <!-- If images are added to gallery, show Photos link and open gallery in modal --> <!-- Add integer after ID --> <?php if( get_sub_field('manufacturing_grid_gallery') ): ?> <a href="#" data-reveal-id="manufacuring-gallery-<?php echo $i; ?>">View Photos</a> <div id="manufacuring-gallery-<?php echo $i; ?>" class="reveal-modal" data-reveal aria-labelledby="modalTitle" aria-hidden="true" role="dialog"> <?php the_sub_field('manufacturing_grid_gallery'); ?> </div> <?php $i++; //Only increment if we had a gallery.. move this outside the last div but inside endwhile if you want it to increment regardless ?> <?php endif; ?> </div> <?php endwhile; endif; ?>
@stinkykong I can’t see anything wrong with your code.. what is it that’s not working according to what you expect?
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.