wordpress函数wp_get_attachment_image

2021年9月18日 飞飞 阅读(826)
知识付费主题,优惠促销中:xx-blog主题

描述

通过id获取缩略图的图片信息,注意一点是这个获取的图片信息带img标签

用法

wp_get_attachment_image( $attachment_id, $size, $icon, $attr );

参数

$attachment_id

(integer) (必填) 附件ID

默认值: None

$size

(string/array) (可选) 图像大小。字符串关键字(缩略图、中、大或全)或以像素表示宽度和高度的两项数组,例如数组(32,32)。从2.5版起,此参数不影响媒体图标的大小,媒体图标始终以其原始大小显示。

默认值: ‘thumbnail’

不要使用需要检查所有图像大小的数组,应该考虑使用add_image_size注册大小,以便生成裁剪版本。它比找到最接近的图像更有效.

$icon

(boolean) (可选) 使用媒体图标表示附件。

默认值: ‘False’

1 (True)
0 (False) – 默认
$attr

(string/array) (可选) 查询字符串或属性数组。

默认值: None

示列

$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID
);

$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo '<li>';
echo wp_get_attachment_image( $attachment->ID, 'full' );
echo '<p>';
echo apply_filters( 'the_title', $attachment->post_title );
echo '</p></li>';
}
}

endwhile;


关注微信公众号『xx主题网

第一时间了解最新网络动态
关注博主不迷路~

未经允许不得转载:xx主题网 » wordpress函数wp_get_attachment_image
分享到:

评论抢沙发

要发表评论,您必须先

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

扫码关注微信公众号

扫描关注xx主题网