I have a repeater filed called “images” and inside it I have a sub_filed called “image”.
How can I get only the first row value?
Here is my code
<?php if( have_rows('images') ): ?>
<?php
$active = 'active';
while ( have_rows('images') ) : the_row();
$image = get_sub_field('image');
if($image == "" ) continue;
?>
<img src="<?php echo get_template_directory_uri(); ?>/files/images/<?php the_sub_field('image'); ?>" class="img-fluid" />
<?php $active = '';
endwhile;
?>
<?php endif; ?>
What I tried (this results in an error)
<?php if( have_rows('images') ): ?>
<?php
$active = 'active';
while ( have_rows('images') ) : the_row();
$image = get_sub_field('image');
if($image == "" ) continue;
?>
<img src="<?php echo get_template_directory_uri(); ?>/files/images/<?php the_sub_field('image'); ?>" class="img-fluid" />
<?php break;
<?php $active = '';
endwhile;
?>
<?php endif; ?>
Many thanks in advance!
The issue is that you have 2 opening <?php
tags without a closing ?>
tag between them (after break;
)