wp_get_attachment_image_src()
wp_get_attachment_image_src( int $attachment_id, string…
wp_get_attachment_image_src( int $attachment_id, string|int[] $size = ‘thumbnail’, bool $icon = false )
检索表示附件的图像。
Retrieves an image to represent an attachment.
目录锚点:#参数#源码#笔记
参数(Parameters)
| 参数 | 类型 | 说明 |
|---|---|---|
| $attachment_id | (int) | 图像附件ID。 |
| $size | (string | int[]) | 图像大小。接受任何有效的图像大小名称,或以像素为单位的宽度和高度值数组(按该顺序)。 |
| $icon | (bool) | 图像是否应返回到mime类型图标。 |
源码(Source)
/**
* Retrieve an image to represent an attachment.
*
* A mime icon for files, thumbnail or intermediate size for images.
*
* @since 2.5.0
*
* @param int $attachment_id Image attachment ID.
* @param string|array $size Optional. Registered image size to retrieve the source for or a flat
* array of height and width dimensions. Default 'thumbnail'.
* @param bool $icon Optional. Whether the image should be treated as an icon. Default false.
* @return false|array Returns an array (url, width, height), or false, if no image is available.
*/
function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = false ) {
// get a thumbnail or intermediate image if there is one
$image = image_downsize( $attachment_id, $size );
if ( ! $image ) {
$src = false;
if ( $icon && $src = wp_mime_type_icon( $attachment_id ) ) {
/** This filter is documented in wp-includes/post.php */
$icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' );
$src_file = $icon_dir . '/' . wp_basename( $src );
@list( $width, $height ) = getimagesize( $src_file );
}
if ( $src && $width && $height ) {
$image = array( $src, $width, $height );
}
}
/**
* Filter the image src result.
*
* @since 4.3.0
*
* @param array|false $image Either array with src, width & height, icon src, or false.
* @param int $attachment_id Image attachment ID.
* @param string|array $size Registered image size to retrieve the source for or a flat
* array of height and width dimensions. Default 'thumbnail'.
* @param bool $icon Whether the image should be treated as an icon. Default false.
*/
return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon );
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 2.5.0 | wp-includes/media.php | 16 | 3 |
笔记(Notes)
return部分提供键,但函数只返回索引。我们应该弄清楚这个函数返回的是什么。一些描述或者链接是中间的
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

还没有任何评论,赶紧来占个楼吧!