i have one page, that could be showing post from category.
i’d using this code
<div id="grid" class="grid-container" style="display: block;">
<ul class="grid columns-2">
<?php
$args = array(
'category' => 0,
'numberposts' => 9,
'post_type' => 'post',
'post_status' => 'publish',
'suppress_filters' => true );
$recent_posts = wp_get_recent_posts($args);
foreach( $recent_posts as $recent ){
echo '<li><a href="' . get_permalink($recent["ID"])
. '" title="'.$recent["post_title"].'" ><img class="aligncenter wp-image-80" src="" alt="'.$recent["post_title"].'"/></a>
<h4>'.$recent["post_title"].'</h4></li> ';
}
?>
</ul>
</div>
and the problem is, i can’t showing the thumbnail.
and i’m trying to find how to get post thumbnail url and put in it
get_the_post_thumbnail is NOT the correct answer since that function call provides you with something like this:
<img src="#">
, and not with some URL only.Well, take this as an example.
For what I have understand you need to get the post thumbnail url only, not the full HTML img object, this is the way you can achieve that:
$args = Arguments for the query.
$data = The query result set.
$something = The array you are going to use to storage the url of the featured image of the set of posts you want to use (in this case is just one, as one of the query arguments said so).
$something[$i][‘id’] = The id of each post you are using.
$post_thumbnail_id = The id of the picture set as featured image in the current post within the media library.
$array_thumbnail = The actual url of the image that you need, as you can see it means that you are getting the src value of the HTML img object currently set as featured image in the current post.
$something[$i][‘image_url’] = That what you look for.
– FUNCTIONS USED –
get_post_thumbnail_id($post_id)
wp_get_attachment_image_src($media_post_id,$size)
Try the below snippet by passing the Post Id.
Refer URL:
https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/
Use get_the_post_thumbnail function.
In this case it is better use The Loop fundamentals of WordPress.
References:
https://codex.wordpress.org/The_Loop
https://codex.wordpress.org/The_Loop_in_Action