
I’ve got a repeat;
<?php if( have_rows('video_profile') ):
$i=1;
?>
<?php while( have_rows('video_profile') ): the_row();
// vars
$video_url = get_sub_field('video_url');
$video_preview_image = get_sub_field('video_preview_image');
$company_logo = get_sub_field('company_logo');
$snippet = get_sub_field('snippet');
?>
<a class="video fancybox-youtube" href="<?php if( $video_url ): ?><?php echo $video_url; ?><?php endif; ?>">
<div class="bg-image" style="background-image:url('<?php if( $video_preview_image ): ?><?php echo $video_preview_image; ?><?php endif; ?> ');">
<div class="company-logo">
<img src="<?php if( $company_logo ): ?><?php echo $company_logo; ?><?php endif; ?> " alt="">
</div>
<div class="snippet-full">
<?php if( $snippet ): ?>
<?php echo $snippet; ?>
<?php endif; ?>
</div>
<div class="snippet">
<?php if( $snippet ): ?>
<?php echo $snippet; ?>
<?php endif; ?>
</div>
<div class="overlay"></div>
</div>
</a>
<?php
$i++;
endwhile; ?>
<?php endif; ?>
And I’m wondering if it’s possible to count how many repeats there are and if there is only 1 to display it a certain way and if there are more than 1 to display it another way?
Thanks 🙂
If you do this for the repeater field
$rows = get_field('video_profile');
$rows will be an array of all of the rows in the repeater, then
if (count($rows) == 0) {
// no rows
} elseif (count($rows) == 1) {
// display 1 row
} else {
// display multiple rows
}
Brilliant, thanks John 🙂