Home › Forums › Add-ons › Repeater Field › First row of repeater field that returns Image Object › Reply To: First row of repeater field that returns Image Object
That worked! Thank you! My code may not be as elegant as it should be. Here is what I did:
<?php if( have_rows('slider') ): ?>
<?php while( have_rows('slider') ): the_row();
$image = get_sub_field('slide');
$rows = get_field('slider', false, false); // get all the rows
$first_row = $rows[0]; // get the first row
$first_row_image = $first_row['slide']; // get the sub field value
?>
<div class="mobile-bg visible-xs" style="background-image:<?php echo $image['url']; ?>"></div><!-- end mobile-bg -->
<?php break; ?>
<?php endwhile; ?>
<?php endif; ?>
I am open to suggestions to make my code better.
Thanks again!
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.