媒体上传URL或URL循环-Wordpress

时间:2013-08-09 21:56:45

标签: php wordpress

我创建了一个自定义图库滑块,我希望将其连接到帖子和网页创建者内部的媒体上传图库功能。

问题是我似乎无法理解如何从媒体上传库中获取原始URL循环,因为如果我现在使用媒体上传功能添加图像,它会给我一个看起来像这样的输出。

<div id="gallery-1" class="gallery galleryid-81 gallery-columns-9 gallery-size-thumbnail"><dl class="gallery-item">
            <dt class="gallery-icon landscape">
                <a href="url.com" title="jay-z+2"><img width="150" height="150" src="#" class="attachment-thumbnail" alt=""></a>
            </dt></dl><dl class="gallery-item">
            <dt class="gallery-icon landscape">
                <a href="#" title=""><img width="150" height="150" src="#" class="attachment-thumbnail" alt=""></a>
            </dt></dl><dl class="gallery-item">
            <dt class="gallery-icon landscape">
                <a href="url.com" title=""><img width="150" height="150" src="#" class="attachment-thumbnail" alt=""></a>
            </dt></dl>
</div>

我想要像

这样的东西
<img width="150" height="150" src="#" class="attachment-thumbnail" alt="">
<img width="150" height="150" src="#" class="attachment-thumbnail" alt="">
<img width="150" height="150" src="#" class="attachment-thumbnail" alt="">

这甚至可能吗?我真的不想使用插件

1 个答案:

答案 0 :(得分:1)

获取网址 - 运行查询

$query_images_args = array(
    'post_type' => 'attachment', 'post_mime_type' =>'image', 'post_status' => 'inherit', 'posts_per_page' => -1,
);

$query_images = new WP_Query( $query_images_args );
$images = array();
foreach ( $query_images->posts as $image) {
    $images[]= wp_get_attachment_url( $image->ID );
}