2011-04-23 76 views
0

我正在上传项目中的一些pdf文件和.doc/docx文件。 因此,我在循环内插入了一个链接附件文件,并且工作正常。如何检索当前获取附件的MIME类型

但我需要得到一个特定的属性:mimetype。

所以,我需要打印附件的URL和MIME类型,像http://domain.com/wp-content/...file.pdf 文件类型此

下载文件:PDF或应用程序/ PDF

有人能帮助我吗?

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

非常感谢。

弗拉维奥

回答

3

如果您确实与环内的附件支柱式处理,你应该能够访问post_mime_type:

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

global $post可能已经被确定,但如果不是,它对于访问发布数据是必要的。

+0

嗨沙丁鱼的功能,我看着文件忽略原始在行911,我用这个了成功:

  • 下载文件: '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); } } ?>
  • 文件类型:<?php echo $ attachment-> post_mime_type; ?>
  • \t Tks for your help – user3157718 2011-04-23 21:56:39

    +0

    好价钱!如果此答案解决了您的问题,请将此标记为已接受。谢谢! – tollmanz 2011-04-23 22:02:51

    3

    有针对

    echo get_post_mime_type();