Home › Forums › Add-ons › Gallery Field › display first gallery picture on archive page › Reply To: display first gallery picture on archive page
For anyone else looking for this I’ve found a solution, probably not the best but it works!
The featured image code higher in the page sets an ‘$image_url’ here:
<?php
$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,’large’);
$image_url = $image_url[0];
echo ‘‘;
the_post_thumbnail(‘medium’);
echo ‘‘; ?>
Then I just compare the gallery image to that and hide if they are the same
<?php $images = get_field(‘image_gallery’);
if( $images ) { ?>
<div id=”imagegallery”>
<?php foreach( $images as $image ) {
if ($image_url != $image[‘url’]) {
?>
” rel=”shadowbox[gallery]” >” alt=”<?php echo $image[‘alt’]; ?>” class=”alignleft” />
<?php } //End URL Check (to hide featured in gallery)
} // End image loop ?>
</div>
<?php } ?>
UPDATE – Editor has made a bit of a mess of the above, but you get the principal!
Lee
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.