获取除特色图片以外的所有帖子附件


8
$args = array(
    'post_type' => 'attachment',
    'numberposts' => null,
    'post_status' => null,
    'post_parent' => $post->ID
);
$attachments = get_posts($args);
if ($attachments) {
    foreach ($attachments as $attachment) {
        echo apply_filters('the_title', $attachment->post_title);
        the_attachment_link($attachment->ID, false);
    }
}

在上面的代码中,存在一种获取方法:

  1. 除特色图片外,所有附件链接。

  2. 仅所有PDF附件链接。

我正在阅读:

Answers:


14

对于第一个,你可以添加'exclude' => get_post_thumbnail_id()作为参数(如图所示这里)。

对于第二个,您可以添加'post_mime_type' => 'application/pdf',但是我不确定那将一直有效,afaik,pdf具有多个mime类型。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.