从get_the_post_thumbnail获取图像源($ post-> ID);

时间:2013-01-16 13:17:12

标签: php html5 wordpress

我必须从下面的代码中获取图像源。

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

我来了

<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">

我想得到这个部分。

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

我如何获得来源?

3 个答案:

答案 0 :(得分:24)

$post_thumbnail_id = get_post_thumbnail_id($post->ID);
$post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );

答案 1 :(得分:1)

这就是你想要的,更简洁:

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

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

您可以获取任何缩略图大小的网址,因此它非常实用。

答案 2 :(得分:-2)

先生,

$post_thumbnail_url = wp_get_attachment_thumb_url($post->ID);
相关问题