I got it, my code is now:
<?php if ( have_rows('apartamento_1_alcoba') ): ?>
<div id="img-module-slider-1" class="vivienda-slider">
<?php while( have_rows('apartamento_1_alcoba') ) : the_row();
$icono_1_alcoba = get_sub_field('icono');
$gallery = get_sub_field('lightbox');
$id_1_alcoba = get_sub_field('plano_id');
?>
<section data-featherlight-gallery data-feather-filter="a">
<a class="apt-gallery-<?php echo $id_1_alcoba ?>" href="<?php echo $gallery[0]['url'] ?>">
<img class="module-img-size" src="<?php echo $icono_1_alcoba['url'] ?>" alt="<?php echo $icono_1_alcoba['alt'] ?>">
</a>
<?php if ( $gallery ): ?>
<?php unset($gallery[0]); ?>
<?php foreach ( $gallery as $image ): ?>
<a class="apt-gallery-<?php echo $id_1_alcoba ?>" href="<?php echo $image['url'] ?>" alt="<?php echo $image['alt']?>"></a>
<?php endforeach; ?>
<?php endif; ?>
</section>
<?php endwhile; ?>
</div>
<?php endif; ?>
Another question, how do I omit the first image in the gallery from the loop?
<?php foreach ( $gallery as $image ): ?>
<a class="apt-gallery-<?php echo $id_1_alcoba ?>" href="<?php echo $image['url'] ?>" alt="<?php echo $image['alt']?>"></a>
<?php endforeach; ?>
Another question, how do I remove the first image from the gallery, I get the first image repeating itself.
<?php if ( have_rows('apartamento_1_alcoba') ): ?>
<div id="img-module-slider-1" class="vivienda-slider">
<?php while( have_rows('apartamento_1_alcoba') ) : the_row();
$icono_1_alcoba = get_sub_field('icono');
$gallery = get_sub_field('lightbox');
$id_1_alcoba = get_sub_field('plano_id');
?>
<section data-featherlight-gallery data-feather-filter="a">
<a class="apt-gallery-<?php echo $id_1_alcoba ?>" href="<?php echo $gallery[0]['url'] ?>">
<img class="module-img-size" src="<?php echo $icono_1_alcoba['url'] ?>" alt="<?php echo $icono_1_alcoba['alt'] ?>">
</a>
<?php if ( $gallery ): ?>
<?php foreach ( $gallery as $image ): ?>
<a class="apt-gallery-<?php echo $id_1_alcoba ?>" href="<?php echo $image['url'] ?>" alt="<?php echo $image['alt']?>"></a>
<?php endforeach; ?>
<?php endif; ?>
</section>
<?php endwhile; ?>
</div>
<?php endif; ?>
Figured it out?
<?php echo $gallery[0]['url'] ?>
I’ve decided to do something like this using a repeater field… not the prettiest thing but it will probably work the way I need it too.
<?php if ( have_rows('apartamento_1_alcoba') ): ?>
<div id="img-module-slider-1" class="vivienda-slider">
<?php while( have_rows('apartamento_1_alcoba') ) : the_row();
$icono_1_alcoba = get_sub_field('icono');
$gallery = get_sub_field('lightbox');
$id_1_alcoba = get_sub_field('plano_id');
?>
<section data-featherlight-gallery data-feather-filter="a">
<?php if ( $gallery ): ?>
<?php foreach ( $gallery as $image ): ?>
<a class="apt-gallery-<?php echo $id_1_alcoba ?>" href="#" data-featherlight="image">
<img class="module-img-size" src="<?php echo $icono_1_alcoba['url'] ?>" alt="<?php echo $icono_1_alcoba['alt'] ?>">
</a>
<a class="apt-gallery-<?php echo $id_1_alcoba ?>" href="<?php echo $image['url'] ?>" alt="<?php echo $image['alt']?>"></a>
<?php endforeach; ?>
<?php endif; ?>
</section>
<?php endwhile; ?>
</div>
<?php endif; ?>
However, I’d like to be able to get just the first image of the gallery in the for each, how can I do that?
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.