wordpress文章函数:get_post_mime_type()


【说明】
按ID编号检索附件的mime类型。
该函数可用于任何文章类型,但更适用于附件类型。
【用法】

  1. <?php get_post_mime_type( $ID ) ?>

【参数】
$ID
(整数)(可选)文章ID
默认值:”
返回的值
(布尔型|字符)
返回mime类型,出错时则返回False。
【示例】

  1. <?php
  2. $mime_type=get_post_mime_type( 36 );//假设id为36的文章是图片类型是“image/jpeg”
  3. echo $mime_type;

//打印出image/jpeg
?>
修改记录
自2.0.0版本后
【源文件】
get_post_mime_type() 位于wp-includes/post.php中。

  1. /**
  2. * Retrieve the mime type of an attachment based on the ID.
  3. *
  4. * This function can be used with any post type, but it makes more sense with
  5. * attachments.
  6. *
  7. * @since 2.0.0
  8. *
  9. * @param int $ID Optional. Post ID.
  10. * @return bool|string False on failure or returns the mime type
  11. */
  12. function get_post_mime_type($ID = '') {
  13. $post = & get_post($ID);
  14.  
  15. if ( is_object($post) )
  16. return $post->post_mime_type;//就是返回post_mime_type字段的值
  17.  
  18. return false;
  19. }