Get the image source from get_the_post_thumbnail($

2019-04-27 21:15发布

I have to get the image source from the code below.

  $thumburl = get_the_post_thumbnail($post->ID);

Here I'm getting

<img width="325" height="202" src="http://localhost/TantraProjects/Border-fall/Repo/WebApp/wp-content/uploads/2012/12/film.png" class="attachment-post-thumbnail wp-post-image" alt="film" title="film">

I want to get this part.

"http://localhost/TantraProjects/Border-fall/Repo/WebApp/wp-content/uploads/2012/12/film.png"

How can I get the source ?

3条回答
Root(大扎)
2楼-- · 2019-04-27 21:27

This is what you want, more concise:

get_the_post_thumbnail_url($post->ID, $size);

https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_url/

You can get the url for any thumbnail size, so its quite a useful function.

查看更多
Fickle 薄情
3楼-- · 2019-04-27 21:40
$post_thumbnail_id = get_post_thumbnail_id($post->ID);
$post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );
查看更多
该账号已被封号
4楼-- · 2019-04-27 21:47

there sir,

$post_thumbnail_url = wp_get_attachment_thumb_url($post->ID);
查看更多
登录 后发表回答