Hirohito Yamada
Hirohito Yamada

Reputation: 387

How to show post thumbnail in wordpress front page

I have following code written in function.php in my wordpress.

function wptuts_recentpost2($atts, $content=null){
$getpost = get_posts( array('number' => 1, 'offset' => 1) );
$getpost = $getpost[0];
$return = $getpost->post_thumbnail . "<br />" . $getpost->post_title . "<br />" . $getpost->post_excerpt . "…";
$return .= "<br /><a href='" . get_permalink($getpost->ID) . "'><em>read more →</em></a>";
return $return;
}
add_shortcode('newestpost2', 'wptuts_recentpost2');

What should I write here to display thumbnails?

I tried adding

$getpost = $get_post->post_thumbnail

But it didn't work... :(

Thank you for your time!

Upvotes: 0

Views: 62

Answers (1)

Stanley Wang
Stanley Wang

Reputation: 1164

You could use get_the_post_thumbnail($getpost->ID).

Please refter to the codex https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/

This will return the thumbnail image tag.

Upvotes: 2

Related Questions