0

I have used the following code to display the featured image for each post, but nothing is showing:

     <div class="thumbnail-img">

<?php 




        $lastBlog = new WP_Query('type=post&posts_per_page=2&offset=1');

        if ($lastBlog->has_post_thumbnail()) {

            while($lastBlog->has_post_thumbnail()) {
                $lastBlog->the_post_thumbnail();
            } ?>

            <?php get_template_part('content-image', get_the_post_thumbnail()); 

        }




?>

</div>
<br>

<?php



        if( $lastBlog->have_posts()):

        while($lastBlog->have_posts()): $lastBlog->the_post(); ?> 



            <?php get_template_part('content-title', get_post_format()); ?>




        <?php endwhile;

    endif;

    wp_reset_postdata();
?>
</div>

How do I resolve this?

1
<div class="thumbnail-img">
<?php 
    $lastBlog = new WP_Query('post_type=post&posts_per_page=2');
    if ($lastBlog->have_posts()) {
        while($lastBlog->have_posts()) {
             $lastBlog->the_post();
              if(has_post_thumbnail()){
                  the_post_thumbnail();
             }
         }
     }
  ?>
 </div>

-> Try Like This

0

I use this way:

$args = array ( 'post_type' => 'slider');
$slides = get_posts( $args );

foreach($slides as $row){ 
    $image = wp_get_attachment_image_src(get_post_thumbnail_id($row->ID),"full");
    echo $image[0];
}
  • I'm not using an image slider. All I wanted it to be able to display the thumbnail over the post title. I have edited the question to show exactly what I wanted. – Michael Stokes Aug 21 '16 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.