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>
原文:https://www.javaroad.cn/questions/3222
参考官方文档:https://developer.wordpress.org/reference/functions/get_attached_media/
声明:本文采用 BY-NC-SA 协议进行授权,如无注明均为原创,转载请注明转自 你好!刘
本文地址:WordPress使用get_attached_media函数获取图片附件
本文地址:WordPress使用get_attached_media函数获取图片附件
发表评论