Home Forums Add-ons Repeater Field Changing the integer in a loop


Changing the integer in a loop

    • chrisfry

    • September 26, 2013 at 4:44 am

    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>
    					<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="" />
    					<!-- lightbox ends -->
    			<div class="menuMiddle2">
    			<p><?php the_sub_field('description'); ?></p>
    			<div class="spacer"><!--blank--></div>
    <?php endwhile; ?>
    <?php endif; ?>
    • Elliot

    • September 30, 2013 at 12:06 pm

    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; ?>">
    <?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?


  • Thanks so much for the help. This worked perfectly.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

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.