描述:
返回附件的缩略图(特色图像)URL网址
用法:
<?php wp_get_attachment_thumb_url( $attachment_id ); ?>
参数:
$attachment_id
(integer) (可选) 附件ID
默认值: 0
示例:
<?php
$thumb_id = 25;
$url = wp_get_attachment_thumb_url( $thumb_id );
?>
<img src="<?php echo $url ?>"/>
源文件:
/**
* Retrieve URL for an attachment thumbnail.
*
* @since 2.1.0
*
* @param int $post_id Optional. Attachment ID. Default 0.
* @return string|false False on failure. Thumbnail URL on success.
*/
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);
/**
* Filter 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 );
}
发表评论
还没有评论,快来抢沙发吧!