wp_get_attachment_image()通过id获取缩略图(特色图像)的图片信息

目录

描述

译文

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

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

原文

Returns an HTML image element representing an attachment file, if there is any, otherwise an empty string.

wp_get_attachment_image() 描述

用法

<?php wp_get_attachment_image$attachment_id$size$icon$attr ); ?>

wp_get_attachment_image() 用法

参数

$attachment_id

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

默认值: None

$size

(string/array) (可选) Image size. 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'

Instead of using an array which requires checking all of the image sizes, you should consider registering a size with add_image_size so that a cropped version is generated. It's much more efficient than having to find the closest sized image.

$icon

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

默认值: 'False'

  • 1 (True)
  • 0 (False) - Default

$attr

(string/array) (可选) Query string or array of attributes.

默认值: None

The $attr argument is merged with WordPress's default attributes and passed through the wp_get_attachment_image_attributes filter.

wp_get_attachment_image() 参数

示例

Display all images as a list

To display all of the images and titles attached to a certain page and display them as a list of bullets you can use the following:

wp_get_attachment_image() 示例

历史

添加于 版本: 2.5.0

wp_get_attachment_image() 历史

源文件

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

wp_get_attachment_image() 源文件

相关