【问题标题】:How to retrieve mime type for the current get attachment如何检索当前获取附件的 MIME 类型
【发布时间】:2011-08-11 15:26:03
【问题描述】:

我正在一个项目中上传一些 pdf 文件和 .doc/docx 文件。 所以,我在循环中插入了一个链接附件文件并且工作正常。

但我需要获取一个特定的属性:mimetype。

所以,我需要打印附件 url 和 mimetype,像这样

http://domain.com/wp-content/...file.pdf上下载文件 文件类型:pdf或应用程序/pdf

有人可以帮我解决这个问题吗?

顺便说一句,我使用的是自定义主题,而不是默认的 wordpress 主题。

非常感谢。

弗拉维奥

【问题讨论】:

    标签: wordpress mime-types attachment


    【解决方案1】:

    如果您确实在循环内处理附件帖子类型,您应该能够访问 post_mime_type:

    global $post;
    $mime_type = $post->post_mime_type;
    

    global $post 可能已经设置,但如果没有设置,则需要访问帖子数据。

    【讨论】:

    • 嗨沙丁鱼,我在第 911 行查看了 media.php 文件,我使用这个成功了:
    • 下载文件:'attachment ', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID ); $attachments = get_posts($args); if ($attachments) { foreach ( $attachments as $attachment ) { the_attachment_link( $attachment->ID , false ); } } ?>
    • 文件类型:post_mime_type; ?>
    • 感谢您的帮助
    【解决方案2】:

    有一个功能

    echo get_post_mime_type();
    

    【讨论】:

      猜你喜欢
      相关资源
      最近更新 更多
      热门标签