Can't get WP thumbnail image

Hey, I’m using the following code for a custom slider, but I’m not able to get the post thumbnail image. I have tried with many functions but nothing worked out. Everything else is working, just the thumbnail image is an issue. If you can help me, it would be really nice.

The code is:

function last_posts( $object ) {
 $args = array( 'numberposts' => '5' );
 $recent_posts = get_posts( $args );
 echo '<ul class="newsbox clear">';
 foreach ( $recent_posts as $recent ) {
  setup_postdata($recent);
  echo '<li><a class="title" href="' . get_permalink($recent) . '">' . get_the_title($recent) . '</a><span class="img"><img alt="alt" src="/images/img.jpg" width="340" height="191"></span><span class="posted">Published on: ' . get_the_date('d.m.Y',$recent) . '</span><span class="text">' . get_the_excerpt($recent) . '</span></li> ';
 }
 echo '</ul>';
 wp_reset_postdata();
}

add_shortcode( 'last5posts', 'last_posts' );

Hi @mikemiller7. I’m going to move your thread to the WordPress category. I think you will probably get more response there where people are familiar with the WordPress functions.

I want to create a blog at my website - and I need that post thumbnail image. Can someone help me?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.