【问题标题】:How to get image attachments from multiple (specified) posts如何从多个(指定)帖子中获取图像附件
【发布时间】:2012-06-15 04:39:03
【问题描述】:

我正在寻找一种提取缩略图的方法以及从多个指定帖子 ID 中提取图像附件的大图像(用作迷你画廊)的来源。

基本上是一种将所有图像组合到一个迷你图库中的帖子附件查询。

我已经了解如何从单个帖子中提取图片附件,但不知道如何从多个帖子中提取图片附件?

换句话说,我们可以从指定的帖子数组中提取图片附件吗?

下面是我用来拉取整个网站所有附件的代码:

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

【问题讨论】:

  • 你加粗指定,然后说但不知道如何从多个帖子中提取图片附件?有什么问题?实际的图像功能是Here & Here
  • 一次从多个帖子中提取图像附件...假设我有 3 个帖子 - 我只想从这 3 个帖子中提取所有图像附件。
  • 或者更好——指定父页面的帖子 ID 并从其子页面中提取所有附件..
  • 你找到这个@Joe 的答案了吗?

标签: php mysql wordpress


【解决方案1】:

经过大量搜索,我不得不得出结论,仅使用一个 WP_query 没有优雅的方法可以做到这一点。相反,您可以为每个 post_id 调用一个新查询,并将生成的附件 ID 组合到一个数组中。将此数组用于您的进一步目的。

【讨论】:

    猜你喜欢
    • 2013-09-21
    • 1970-01-01
    • 2011-10-13
    • 2016-05-04
    • 1970-01-01
    • 2013-07-27
    • 1970-01-01
    • 2017-07-08
    • 2013-10-09
    相关资源
    最近更新 更多