Home › Forums › Add-ons › Repeater Field › Changing the integer in a loop
I’m using the Repeater plugin along with FancyBox and can’t figure out how to update the numbers in a loop required to launch the correct lightbox. I’ve searched around and tried various solutions, but none seem to be working for me. Here’s the code I’m working with, the integers that need to be updated in the loop are “various1”, “#inline1”, and “inline1”.
<?php if(get_field('menu_item')): ?>
<?php while(has_sub_field('menu_item')): ?>
<div class="menuBox">
<div class="menuTop">
<div class="menuBottom">
<img src="<?php the_sub_field('food_photo'); ?>" width="161" height="102" alt="" />
<div class="menuContent">
<h3><?php the_sub_field('name'); ?></h3>
<div class="pricePan">
<div class="price">
<p><?php the_sub_field('price'); ?></p>
</div>
<a id="various1" href="#inline1" class="menuMore">More</a>
<!-- lightbox starts -->
<div style="display: none;">
<div id="inline1>
<div class="popbox">
<div class="popupdefaultdiv">
<div class="popupdescription">
<h2 class="popupheading"><?php the_sub_field('name'); ?></h2>
<p class="popupProductDescription"><?php the_sub_field('description'); ?></p>
<img src="<?php the_sub_field('food_photo'); ?>" width="607" alt="" />
</div>
</div>
</div>
</div>
</div>
<!-- lightbox ends -->
</div>
<div class="menuMiddle2">
<p><?php the_sub_field('description'); ?></p>
</div>
<div class="spacer"><!--blank--></div>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
Hi @chrisfry
Sounds like you need to use a counter variable to dynamicaly echo the row number. You can do this like so:
<?php if(get_field('menu_item')): $i = 0; ?>
<?php while(has_sub_field('menu_item')): $i++; ?>
<div id="test-<?php echo $i; ?>">
</div>
<?php endwhile; ?>
<?php endif; ?>
Note that the variable $i will increment each row, and you can render it with the echo function.
Does that help?
Cheers
E
The topic ‘Changing the integer in a loop’ is closed to new replies.
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.