wp_get_attachment_image_src()获取缩略图(特色图像)的路径(可定义图片的长宽)

目录

描述

译文

存在图片时,返回代表附件文件的HTML图片标签。否则返回空字符串。

概要

(字符) $image = function wp_get_attachment_image_src($attachment_id, $size='thumbnail', $icon = false);

原文

Returns an ordered array with values corresponding to the (0) url, (1) width, (2) height, and (3) scale of an image attachment (or an icon representing any attachment).

It's most often used to get the URL (src) for an image attachment: use the first element in the returned array.

wp_get_attachment_image() uses wp_get_attachment_image_src() to fill the width, height, and src attributes of an img.

wp_get_attachment_image_src() 描述

用法

 <?php wp_get_attachment_image_src$attachment_id$size$icon ); ?> 

wp_get_attachment_image_src() 用法

参数

$attachment_id

(integer) (必填) ID of the desired attachment.

默认值: None

$size

(string/array) (可选) Size of the image shown for an image attachment: either a string keyword (thumbnail, medium, large, or full), or a 2-item array representing width and height in pixels, e.g., array(32,32). As of Version 2.5, this parameter does not affect the size of media icons, which are always shown at their original size.

默认值: thumbnail

$icon

(bool) (可选) Use a media icon to represent the attachment.

默认值: false

wp_get_attachment_image_src() 参数

示例

Default Usage

Change Icon Directory

WordPress can use media icons to represent attachment files on your blog and in the Admin interface, if those icons are available. For images, it returns the thumbnail. For other media types, it looks for image files named by media type (e.g., audio.jpg) in the directory: wp-includes/images/crystal/.

This example shows how you can change this directory to a folder called "images" in your theme: wp-content/themes/yourtheme/images. Create the folder and put "media type images" in there. To tell WordPress the directory has changed, put this in the current theme's functions.php file:

Show the first image of the post

find the full code here get_children().

wp_get_attachment_image_src() 示例

历史

添加于 版本: 2.5.0

wp_get_attachment_image_src() 历史

源文件

wp_get_attachment_image_src() 函数的代码位于 wp-includes/media.php.

wp_get_attachment_image_src() 源文件

相关