• Hello, I need to know if it is possible for me to list the first image of each linked gallery in a custom post type I created. I created a sales site where users will add images and I want to get one of those image to leave as a featured image in the post.
    I use the following code in my single.php to list all post photos:

    <?php get_header(); ?>
    
    <div class="list-fotos image-gallery thumbnails-4 linked">
    	<h2><?php the_title(); ?></h2>
    	<span><?php the_time('d/m/Y') ?></span>
    	<?php $images = easy_image_gallery_get_image_ids(); ?>
    
    	<ul>
    		<?php if($images) : foreach ( $images as $attachment_id ):?>
    			<?php $imagefull = wp_get_attachment_image_src ( $attachment_id, '' ); ?>
    			<?php $image = wp_get_attachment_image_src ( $attachment_id, 'thumb-custom' ); ?>
    			<li>
    				
    				<a class="popup" rel="fancybox[group]" href="<?php echo $imagefull[0]; ?>">
    					
    					<img src="<?php echo $image[0]; ?>">
    
    				</a>
    
    			</li>
    		<?php endforeach; endif; ?>
    	</ul>
    </div>
    
    <?php get_footer(); ?>

    In my index.php I want to grab a photo from the gallery and leave it as a featured image, how can I do that?

Viewing 1 replies (of 1 total)
  • I would modify you code as follows

    
    <div class="list-fotos image-gallery thumbnails-4 linked">
       <h2><?php the_title(); ?></h2>
       <span><?php the_time('d/m/Y') ?></span>
       <?php $images = easy_image_gallery_get_image_ids(); ?>
       <?php $image = wp_get_attachment_image_src ( $images[0], 'thumb-custom' ); ?>
       <img src="<?php echo $image[0]; ?>">
    </div>
    
    
    • This reply was modified 7 years, 11 months ago by felixprojekt.
Viewing 1 replies (of 1 total)
  • The topic ‘List a first gallery image’ is closed to new replies.