I have this custom post type Gallery. I want to call first image from the posts.
<?php
$item_count = 1;
$args = array( 'post_type' => 'gallery', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
$item_count = 1;
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php the_title(); ?>
<div class="count"><?php echo $item_count; ?></div>
<div class="thumbnail">
// THE FIRST GALLERY ATTACHMENT IMAGE
</div>
<?php $item_count++; ?>
<?php endwhile; ?>
Any ideas?
Note: I added Gallery no simple image on the post!
Check this WordPress Codex example.
The code will show the first image associated with the post.
Or check this WordPress forum discussion that also deals with this problem.
UPDATE:
Go to Appearance > Editor and select Theme functions (functions.php).
at the end of the file add this:
Now in your code you modify this part of the code:
UPDATE V2
I modified the code to suit your code.
UPDATE V3
I tried the code on my development site and I modified it further until the code worked as it should. You should not have any problems now.