得到wordpress所有媒体文件的功能是什么? [英] What is the function got get all the media files wordpress?

查看:27
本文介绍了得到wordpress所有媒体文件的功能是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能建议我为wordpress存储所有图像的功能是什么?我只需要列出 wordpress 管理员菜单 Media 下看到的所有图像.

Can anyone suggest me what is the function to get all the images stored for wordpress? I just need to list all the images seen under menu Media of the wordpress admin.

提前致谢

推荐答案

上传的图片存储为附件"类型的帖子;使用具有正确参数的 get_posts().在 get_posts() 的 Codex 条目 中,此示例:

Uploaded images are stored as posts with the type "attachment"; use get_posts() with the right parameters. In the Codex entry for get_posts(), this example:

<?php

$args = array(
    'post_type' => 'attachment',
    'numberposts' => -1,
    'post_status' => null,
    'post_parent' => null, // any parent
    ); 
$attachments = get_posts($args);
if ($attachments) {
    foreach ($attachments as $post) {
        setup_postdata($post);
        the_title();
        the_attachment_link($post->ID, false);
        the_excerpt();
    }
}

?>

...遍历所有附件并显示它们.

...loops through all the attachments and displays them.

如果您只想获取图像,正如 TheDeadMedic 评论的那样,您可以使用 'post_mime_type' => 进行过滤.'image' 在参数中.

If you just want to get images, as TheDeadMedic commented, you can filter with 'post_mime_type' => 'image' in the arguments.

这篇关于得到wordpress所有媒体文件的功能是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆