检索附件缩略图的URL。
原型
wp_get_attachment_thumb_url( int $post_id )
参数
$post_id
(int)
(Optional)
附件ID。默认值为0。
返回值
(string|false)
失败时是假的。成功时的缩略图URL。
源文件
路径:wp-includes/post.php
<?php
...
function wp_get_attachment_thumb_url( $post_id = 0 ) {
$post_id = (int) $post_id;
if ( !$post = get_post( $post_id ) )
return false;
if ( !$url = wp_get_attachment_url( $post->ID ) )
return false;
$sized = image_downsize( $post_id, 'thumbnail' );
if ( $sized )
return $sized[0];
if ( !$thumb = wp_get_attachment_thumb_file( $post->ID ) )
return false;
$url = str_replace(basename($url), basename($thumb), $url);
/**
* Filters the attachment thumbnail URL.
*
* @since 2.1.0
*
* @param string $url URL for the attachment thumbnail.
* @param int $post_id Attachment ID.
*/
return apply_filters( 'wp_get_attachment_thumb_url', $url, $post->ID );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_get_attachment_thumb_url/