12
A
回答
23
上传图像被存储为与类型“附件”的帖子;使用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'
进行过滤。
1
<ul>
<?php if (have_posts()) : while (have_posts()) : the_post();
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
echo '<li>';
echo wp_get_attachment_image($attachment->ID, 'full');
echo '<p>';
echo apply_filters('the_title', $attachment->post_title);
echo '</p></li>';
}
}
endwhile; endif; ?>
</ul>
+0
我是否需要创建一个新页面? – TheBlackBenzKid 2016-09-19 05:44:29
相关问题
- 1. 获得没有SDP文件的RTP流媒体功能(Gstreamer)
- 2. Wordpress - 拥有插件 - 获取媒体库的所有图像
- 3. 所有类型媒体的Wordpress画廊?
- 4. 什么是存储媒体文件的有效方法?
- 5. 获得核心WordPress功能
- 6. 如何在WordPress中重命名所有媒体文件?
- 7. 什么是获取ExtJs面板中所有项目的功能
- 8. 什么是所有文件
- 9. 文件/文件夹权限和所有权打破了WordPress的功能,什么是安全解决方案?
- 10. 如何在wordpress中获得现有媒体的网址
- 11. 从wordpress中的某个上传位置获取所有媒体
- 12. wordpress-java API |如何获得帖子的媒体附件链接?
- 13. 如何动态获取/ res/raw中的所有媒体文件?
- 14. 获取Android 2.3中的所有非媒体文件
- 15. 如何获取计算机上的所有媒体文件
- 16. 为什么我不能获得我的$文档就绪功能
- 17. 什么是最好的做法,称为wordpress媒体上传(wp.media)
- 18. 为什么Django不能提供我的媒体文件?
- 19. c从C++获得了什么功能?
- 20. 什么是所有可能的断言功能?
- 21. 如何获得媒体附件链接没有任何链接在WordPress的
- 22. Symfony 2获得实体类中的Sonata媒体文件路径
- 23. 创建一个包含所有功能的wordpress文件
- 24. 我怎么能用WinAPI获得文件所有者C++
- 25. CSS媒体查询功能
- 26. 获得所有文件从MongoDB的,而不是所有型号
- 27. 在Wordpress中有没有像'添加媒体'功能的好宝石?
- 28. WordPress:为什么图像没有保存在媒体库中?
- 29. 如何获得我的摄像头的流媒体RTSP/RTMP网址是什么?
- 30. WordPress的:我如何获得所有'the_content'过滤器的注册功能
是的,你可以用' 'post_mime_type'=>“image''在'$ args',和WordPress会巧妙地搭配,对所有的图像MIME类型:) – TheDeadMedic 2010-07-22 11:31:15
@TheDeadMedic好消息!我从来没有需要回到特定的类型。 – 2010-07-22 12:05:41
对于匹配MIME类型的TheDeadMedic很好的答案和荣誉! :) – hsatterwhite 2010-07-22 12:17:13