Home › Forums › Add-ons › Repeater Field › Split Repeater fields
Hi,
I am trying to grab all of the fields and split them by 16, into separate chunks of HTML. Here is my code which doesn’t really work well at all, for some reason my code isn’t closing the <div class="section">
div in which each 16x fields should be contained.
Any help would be most appreciated.
My code:
<?php $logototal = count( get_sub_field('bp_client_logos') ); //Get a total count of the logos ?>
<?php
$count = "0";
if( have_rows('bp_client_logos') ) :
$i = 1;
while ( have_rows('bp_client_logos') ) : the_row(); ?>
<?php
$clientindex = $i;
if( $clientindex == "1" || ($clientindex-1) %16 == "0" ) :
?>
<div class="section general-section section-<?php echo $title; ?> section-count-<?php echo $count; ?>" data-anchor="section-<?php echo $count; ?>" style="<?php echo $bg_background; ?>">
<div class="row small-up-4 medium-up-8 large-up-8 align-middle">
<?php endif; ?>
<div class="column client-logo-grid">
<?php
$image = get_sub_field('bp_client_logo');
// Vars
$url = $image['url'];
$thistitle = $image['title'];
$alt = $image['alt'];
$caption = $image['caption'];
$size = 'ClientLogo' ;
$thumb = $image['sizes'][ $size ];
?>
<?php if ( get_sub_field('bp_client_link') ) : ?>
<a target="_blank" href="<?php the_sub_field('bp_client_link'); ?>">
<img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>" />
</a>
<?php else: ?>
<img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>" />
<?php endif; ?>
</div><!-- .column -->
<?php if( ($clientindex) %16 == "0") : $count = $count+1; ?>
</div><!-- .row -->
</div><!-- .section -->
<?php endif; ?>
<?php $i++; ?>
<?php endwhile; ?>
<?php endif; ?>
I would do this a little different. I’m only including enough to give you an example
<?php
if (have_rows('bp_client_logos')) {
// there are rows in the repeater
// create counter
$count = 0;
?>
<div class="section"><!-- open first .section -->
<div class="row"><!-- open first .row -->
<?php
while (have_rows('bp_client_logos')) {
the_row();
if (($count%16) == 0 && $count > 0) {
// we have output 16 repeater rows
// and this needs to be the first row of the next section
// close the last row and section opened
// and open a new section and row
?>
</div><!-- close last .row -->
</div><!-- close last .section -->
<div class="section"><!-- open next .section -->
<div class="row"><!-- open next .row -->
<?php
} // end if 16
?>
<div class="column">
and display the rest of the row content here
</div>
<?php
// increment count
$count++;
} // end while have_rows
?>
</div><!-- close last .row -->
</div><!-- close lase .section -->
<?php
} // end if have_rows
?>
The topic ‘Split Repeater fields’ 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.