問題描述

$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);
    }
}

在上面的代碼中,theres 存在一種獲取方式:

  1. 所有附件鏈接除了特色圖片。

  2. 所有 PDF 附件鏈接僅。

我在讀:

最佳解決方案

對於第一個,您可以添加'exclude' => get_post_thumbnail_id()作為參數 (如 here 所示) 。

對於第二個,您可以添加'post_mime_type' => 'application/pdf',但我不確定這將始終工作,afaik,pdfs 有多個 MIME 類型。

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。