wordpress - 得到wordpress所有媒体文件的功能是什么?

标签 wordpress function image

任何人都可以建议我获取为 wordpress 存储的所有图像的功能是什么?我只需要列出在 wordpress 管理员的菜单媒体下看到的所有图像。

提前致谢

最佳答案

上传的图像存储为“附件”类型的帖子;使用具有正确参数的 get_posts()。在 the Codex entry for get_posts() ,这个例子:

<?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();
    }
}

?>

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

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

关于wordpress - 得到wordpress所有媒体文件的功能是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3307576/

相关文章:

php - wordpress 视频不适用于移动设备

php - 检查字符串是否超过限制字符然后显示 '...'

wordpress - 使用 WP_Query() 查询较新的帖子,在 WHERE 过滤器中使用帖子 ID?

javascript - Uncaught ReferenceError : postscribe is not defined at ctkvidinit ((index):3258)

php - 创建过去一周最受欢迎的帖子列表 - Wordpress

javascript - 从函数返回值作为jQuery中参数的值

部分显示的Android WebView图像

ios - NSData 对象因未知原因为空(保存图像)

html - 如果屏幕分辨率超过显示图像?

javascript - jQuery 日期选择器本地化不起作用