I am trying to build a slider using Wordpress Plugin Advanced Custom Fields.
With the plugin, I have made a repeater which contains an image and a caption field (among others).
The code below works, but it seems asinine to have to use so many echo commands (since there are so many html tags.
I’m a PHP novice. Is there a better way to do this?
<div class="slider">
<?php
$rows = get_field('gallery_repeater');
echo "I have a gallery repeater";
if( $rows ) {
foreach( $rows as $row ) {
$repeater_image = $row['gallery_repeater_image'];
$repeater_image_url = $repeater_image['url'];
$default_caption = $row['gallery_repeater_caption'];
if ($default_caption) {
$image_caption = $default_caption;
}
else {
$image_caption = $repeater_image['caption'];
}
echo '<div class="slide"> <img src="';
echo ($repeater_image_url);
echo '">';
echo '<p>';
echo ($image_caption);
echo '</p> </div>';
}
}
?>
</div><!-- end slider -->