我认为这会成功。
// Get ID of the attached file
$thumbnail_id = get_post_thumbnail_id(get_the_ID());
// Get attached file. Define what size at the end. DEfault is the thumbnail.
$image_src_arr = wp_get_attachment_image_src($thumbnail_id,'medium');
// Return image source
$image_source = $image_src_arr[0];
我为 myeslf 创建了这个函数:
/**
* This function will return source url for attached image-
* The get_the_ID is a global WP command that will retrieve current post / page ID
* Using the post ID it will return the attachment ID needed in order to call
* wp_get_Attachment_image_src.
*/
function get_related_image($size){
$image_src_arr = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()),$size);
if(sizeof($image_src_arr) > 0) {
return $image_src_arr[0];
} else {
return false;
}
}