我正在研究带有滑块的wordpress主题。为了显示附加到当前帖子的图像,我使用以下PHP代码:
<?php
$images = get_attached_media('image' ); // get attached media
foreach ($images as $image) {
$ximage = wp_get_attachment_image_src($image->ID,'large');
echo '<div><img src="' .$ximage[0] . '" class="img-responsive" /></div>';
}
?>
输出:
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-1-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-2-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-3-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-4-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-5-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-6-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-7-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-8-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-9-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-10-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-11-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-12-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-13-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-14-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-15-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-16-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-17-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-18-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-19-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-20-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-21-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-22-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-23-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-24-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-25-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-26-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-27-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-28-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-29-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-30-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-31-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-32-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-33-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-34-1024x682.jpg" class="img-responsive" /></div>
我需要执行以下操作的代码:
1 。为图像添加 alt 属性(所有附加图像在后端均具有alt属性)。
2 。更改图像的排序,使输出看起来像这样:
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-5-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-6-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-7-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-8-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-9-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-10-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-11-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-12-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-13-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-14-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-15-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-16-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-17-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-18-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-19-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-20-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-21-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-22-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-23-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-24-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-25-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-26-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-27-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-28-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-29-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-30-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-31-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-32-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-33-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-34-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-1-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-2-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-3-1024x682.jpg" class="img-responsive" /></div>
<div><img src="https://example.com/wp-content/uploads/2018/12/Image_Title-4-1024x682.jpg" class="img-responsive" /></div>
请注意,随着我定期更新博客并不断添加新帖子,“ 2018/12”和“ Image_Title”可能会更改。
谢谢!