如何从多个(指定的)帖子获得图像附件

时间:2022-06-09 19:21:23

I'm looking for a method to pull thumbnails as well as the source for the large image (to be used as a mini gallery) that pulls image attachments from multiple specified post ID's.

我正在寻找一种提取缩略图的方法,以及从多个指定的post ID中提取图像附件的大图(作为一个迷你图库使用)的源。

Basically a query for post attachments that combines all the images into one mini gallery.

基本上是一个将所有图像合并到一个小画廊的post附件的查询。

I've seen how to pull image attachments from a single post, but no idea how to pull image attachments from multiple posts?

我见过如何从一个帖子中提取图片附件,但是不知道如何从多个帖子中提取图片附件。

In other words, can we pull image attachments from a specified array of posts?

换句话说,我们可以从指定的文章数组中提取图像附件吗?

Below is the code i'm using to pull ALL attachments throughout the site:

下面是我用来在整个站点中提取所有附件的代码:

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

1 个解决方案

#1


0  

After much searching I had to conclude there is no elegant way to do this with just one WP_query. Instead you can call a new query for each post_id and combine the resulting attachment ids into one array. Use this array for your further purposes.

在进行了大量搜索之后,我不得不得出结论:仅使用一个WP_query就无法实现这一点。相反,您可以为每个post_id调用一个新的查询,并将生成的附件id合并到一个数组中。将此数组用于进一步的目的。

#1


0  

After much searching I had to conclude there is no elegant way to do this with just one WP_query. Instead you can call a new query for each post_id and combine the resulting attachment ids into one array. Use this array for your further purposes.

在进行了大量搜索之后,我不得不得出结论:仅使用一个WP_query就无法实现这一点。相反,您可以为每个post_id调用一个新的查询,并将生成的附件id合并到一个数组中。将此数组用于进一步的目的。