[TOC]
## **wordpress文章函數:get_post_mime_type()**
### **函數說明**
按ID編號檢索附件的mime類型。
該函數可用于任何文章類型,但更適用于附件類型。
* * * * *
### **函數用法**
~~~
<?php get_post_mime_type( $ID ) ?>
~~~
* * * * *
### **參數說明**
$ID
(整數)(可選)文章ID
默認值:”
* * * * *
### **示例**
~~~
<?php
$mime_type=get_post_mime_type( 36 );//假設id為36的文章是圖片類型是“image/jpeg”
echo $mime_type;
~~~
* * * * *
### **返回值**
返回的值
(布爾型|字符)
返回mime類型,出錯時則返回False。
* * * * *
### **源文件**
~~~
get_post_mime_type() 位于wp-includes/post.php中。
~~~
~~~
/**
* Retrieve the mime type of an attachment based on the ID.
*
* This function can be used with any post type, but it makes more sense with
* attachments.
*
* @since 2.0.0
*
* @param int $ID Optional. Post ID.
* @return bool|string False on failure or returns the mime type
*/
function get_post_mime_type($ID = '') {
$post = & get_post($ID);
if ( is_object($post) )
return $post->post_mime_type;//就是返回post_mime_type字段的值
return false;
}
~~~
* * * * *