如何显示每个附件';WordPress中的个人附件详细信息页面上的ID


How to display each attachment's ID on individual attachment details pages in WordPress?

我正试图在各个附件详细信息页面上显示我的WordPress附件的ID号。我当前的代码可以显示附件ID,但我不知道如何进行工作循环,以便将每个ID显示在自己的附件详细信息页面上。现在,每个附件页面上只有一个身份证号码,同一个。

我尝试过WP_query、query_posts和get_posts。运气不好。这是我的代码,它只是部分工作(因为缺少循环部分),它被放在我的functions.php文件中。

function id_on_attachment_pages() {
    global $post;
    $args = array(
        'post_type' => 'attachment',
    );
    $attachments = get_posts($args);
    if ($attachments) {
        foreach ($attachments as $post) {
            $id = var_dump($post->ID);
        }
    }
    $attachment_id[] = array(
        "label" => "$id",
    );
    return $attachment_id;
}
add_filter("attachment_fields_to_edit", "id_on_attachment_pages");

编辑:这可能有点令人困惑,所以让我澄清一下,我说的是"附件详细信息"页面,而不是附件页面。

试着使用wordpress的全局变量,你不需要发出请求来获得你需要的id。http://codex.wordpress.org/Global_Variables

global $post; 
var_dump($post);

如果需要,不要忘记转义html。