Hi everyone!
I have a serious dude. Is possible show only the first image of Gallery?
Hi @contacto9
Yes, this is possible. The gallery returns an array of image data, so just get the first image $images[0]
I don’t understand sorry. I get gallery with the next code. How can modify for get/show only first image of gallery? Really thanks!
<?php
$images = get_field('images');
if( $images ): ?>
<ul class="imagegallery">
<?php foreach( $images as $image ): ?>
<li>
<a href="<?php echo $image['url']; ?>" rel="lightbox">
<img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />
</a>
<?php echo $image['caption']; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
I have the solution. thanks for your help!!
<?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
<div id="custom-bg" style="background-image: url('<?php echo $image[0]; ?>')">
</div>
<?php endif; ?>