Home › Forums › Add-ons › Gallery Field › Can I add a class to first image in gallery loop › Reply To: Can I add a class to first image in gallery loop
Thanks for this John, I worked this in nicely to an image slider using the Gallery field:
<div class="page-block-right slide-nav-section">
<?php
$images = get_field('gallery');
$size = 'large';
if( $images ): ?>
<?php foreach( $images as $image_id ): ?>
<input type="radio" id="<?php echo $image_id;?>" name="slider" <?php
if ($count == 0) {
echo 'checked';
}
?> >
<label for="<?php echo $image_id;?>"></label>
<div class="slide bg4"><?php echo wp_get_attachment_image( $image_id, $size ); ?></div>
<?php $count++; ?>
<?php endforeach; ?>
<?php endif; ?>
</div>
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.