描述
通过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;
评论抢沙发