wp_get_attachment_image_src
函数
wp_get_attachment_image_src ( $attachment_id, $size = 'thumbnail', $icon = false )
- 参数
-
-
(int)
$attachment_id
Image attachment ID.- Required: 是
-
(string|int[])
$size
Optional. Image size. Accepts any registered image size name, or an array of width and height values in pixels (in that order). Default ‘thumbnail’.- Required: 否
- Default: ‘thumbnail’
-
(bool)
$icon
Optional. Whether the image should fall back to a mime type icon. Default false.- Required: 否
- Default: false
-
(int)
- 返回值
-
- (array|false) { Array of image data, or boolean false if no image is available. @type string $0 Image source URL. @type int $1 Image width in pixels. @type int $2 Image height in pixels. @type bool $3 Whether the image is a resized image. }
- 定义位置
-
-
wp-includes/media.php
, line 952
-
wp-includes/media.php
- 引入
- 2.5.0
- 弃用
- –
Retrieves an image to represent an attachment.
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 ); if ( $src ) { /** 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 ) = wp_getimagesize( $src_file ); } } if ( $src && $width && $height ) { $image = array( $src, $width, $height, false ); } } /** * Filters the attachment image source result. * * @since 4.3.0 * * @param array|false $image { * Array of image data, or boolean false if no image is available. * * @type string $0 Image source URL. * @type int $1 Image width in pixels. * @type int $2 Image height in pixels. * @type bool $3 Whether the image is a resized image. * } * @param int $attachment_id Image attachment ID. * @param string|int[] $size Requested image size. Can be any registered image size name, or * an array of width and height values in pixels (in that order). * @param bool $icon Whether the image should be treated as an icon. */ return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon ); }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。