Home › Forums › Add-ons › Repeater Field › Repeaters/Lightboxes: Dynamically alternating variables › Reply To: Repeaters/Lightboxes: Dynamically alternating variables
Hi @yulichka
There are 2 ways to achieve the above.
The 1st option is more efficient, but will require more code. This is to use an AJAX call to find the HTML instead of creating the inline content. You would need to create a PHP function in your function.php file and attach it to a WP AJAX action. You would then need to write some jQuery on the front end to post through the post_id, row_number and sub_field_name values for the PHP function to then load the flexibel content field and return the data needed.
Your other option is to do what you already have but make some important changes.
your code shows 2 issues:
1. All your inline content is OUTSIDE the loop, so no data will load
2. Your links and inline content id attributes do not contain a row identifier, so your javascript plugin won’t know which one to load.
I think if you added a counter variable for the row number like so, it owuld all work:
<?php if(get_field('media')): $i = 0; ?>
<!-- LINKS TO LIGHTBOXES -->
<ul>
<?php while(has_sub_field('media')): $i++; ?>
<?php $file_type = get_sub_field('file_type'); ?>
<?php if( $file_type === 'audio' ) {?>
<li>
<a href="#audio-popup-<?php echo $i; ?>" class="popup">AUDIO</a>
<!-- INLINE LIGHTBOXES -->
<div id="audio-popup-<?php echo $i; ?>" class="audio popup-container mfp-hide">
<p class="title"><span>Audio Popup</span></p>
<?php the_sub_field('file'); ?>
</div><!--/#still-popup-->
</li>
<?php } ?>
<?php endwhile; ?>
</ul>
<?php endif; ?>
Please note I have removed some code to clarify the solution
Thanks
E
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.