I have a loop that pulls the first three posts of a category. I want to use the featured image of the first post pulled for the background of the section the titles and links to these posts are displayed.
Is it possible to pull the first image without pulling all other images of posts that were pulled in the loop?
Here's the current loop:
<?php
$cinemasight_header_query = new WP_Query( array(
'category_name' => 'academy-awards',
'posts_per_page' => 3
) );
if ($cinemasight_header_query->have_posts()) :
while($cinemasight_header_query->have_posts()) :
$cinemasight_header_query->the_post();?>
<span class="Categories_Upper_Left">
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a><br />
</span>
<?php endwhile;
endif;
wp_reset_postdata();?>
EDIT (8/13/16, 8:56AM CST)
Revised for most recent corrections.
<div class="Header_Section_Left"><span class="Category_Header_Title">ACADEMY AWARDS<br /></span><div id="Header_Upper_Left">
<?php
$cinemasight_header_query = new WP_Query( array(
'category_name' => 'academy-awards',
'posts_per_page' => 3
) );
if ($cinemasight_header_query->have_posts()) :
while($cinemasight_header_query->have_posts()) :
$cinemasight_header_query->the_post();
if( 0 == $cinemasight_header_query->current_post ) :
$thumbnail_id = get_post_thumbnail_id();
$image_src = wp_get_attachment_image_src( $thumbnail_id );?>
<div class="Categories_Upper_Left" style="background-image: url( '<?php echo $image_src[0]; ?>') ;">
<a href="<?php the_permalink() ?>"><?php echo the_title(); ?></a>
</div>
<?php continue;
endif;?>
<span class="Categories_Upper_Left">
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a><br />
</span>
<?php endwhile;
endif;
wp_reset_postdata();?>
</div>
edit
link above and post your loop code please? – Howdy_McGee♦ Aug 11 '16 at 17:24$cinemasight_header_query->the_post();?>
should not have the?>
also you need to add your normal HTML to display the remaining 2 posts (without the image) between theendif
and theendwhile
just after thecontinue
– bynicolas Aug 13 '16 at 0:59get_post_thumbnail
as in my answer. If you choose a different direction, just post a new question. Cheers! – bynicolas Aug 13 '16 at 17:25