Home › Forums › Add-ons › Repeater Field › Repeater row count for nested gallery sub field rel attribute
Hello, I have created a repeater field with a nested gallery field. Everything is working great; however, in order for FancyBox to load each gallery field as separate galleries I need to give each gallery a separate rel attribute. Using $count = $i I can get the count working for the repeater rows but I can’t figure out how to carry that data for use as a rel attribute for the fancybox link. If this is outside the realm of support for this forum, please let me know. I’ve been Googling with results pertaining to repeater fields but I can’t carry the data to the nested galleries. Thanks in advance for any help!
Example:
<a class="fancybox-thumb" rel="fancybox-thumb-1" href="<?php echo $image['url'] ?>" title="<?php echo $image['caption']; ?>">
The pastie below shows my current code:
http://pastie.org/10346781
Hi @inhouse
Well it’s not technically an ACF question (more of PHP) but we’ll be glad to help you none the less!
If I understand you correctly this should do it:
<?php if( have_rows('portfolio_category') ): ?>
<ul class="no-bullet-list photo-gallery-category-list">
<?php $i = 1; ?>
<?php while( have_rows('portfolio_category') ): the_row(); ?>
<li class="portfolio-gallery-category">
<h3><?php echo get_sub_field('portfolio_category_title'); ?></h3>
<?php $portfolio_images = get_sub_field('portfolio_gallery');
if( $portfolio_images ): ?>
<ul class="photo-gallery">
<?php foreach( $portfolio_images as $image ): ?>
<li class="photo">
<a class="fancybox-thumb" rel="fancybox-thumb-<?php echo $i; ?>" href="<?php echo $image['url'] ?>" title="<?php echo $image['caption']; ?>">
<img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>"/>
</a>
</li><!--photo-->
<?php endforeach; ?>
</ul><!--photo-gallery-->
<?php wp_reset_postdata();
endif; ?>
</li><!--portfolio-gallery-category-->
<div class="clr"></div>
<?php $i++; endwhile; ?>
</ul><!--gallery-->
<?php endif; ?>
I have a feeling you overcomplicated it in your head.
Wow, thanks @jonathan I really appreciate the help! Everything is working great!
No problem 🙂 You almost had it with your own code so it was a minor tweak.
Good luck in your project and feel free to post another topic if you need further help with ACF.
The topic ‘Repeater row count for nested gallery sub field rel attribute’ 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.