1 回答
TA贡献1851条经验 获得超5个赞
这将在以下两种情况下起作用:
1)。有一张特色图片,还有第二张图片。
2)。没有特色图片,但有另一张图片
如果内容中有多个图像,则可能需要修改此代码以考虑其他图像 - 但是,key($images)可能只是获取它找到的第一个键。
// Get all the images
$images = get_attached_media('image');
// Get the featured image
$featured_image_id = get_post_thumbnail_id();
// If there is a featured image
if ( has_post_thumbnail() ) {
// Remove the featured image from the images array
unset($images[ $featured_image_id ] );
}
// Set your ximage var to get the src using the key from the $images array - which is the 2nd image ID.
$ximage = wp_get_attachment_image_src( key($images),'medium');
// Echo it out.
echo '<img src="' . $ximage[0] . '">';
- 1 回答
- 0 关注
- 99 浏览
添加回答
举报
