【说明】
按ID编号检索附件的mime类型。
该函数可用于任何文章类型,但更适用于附件类型。
【用法】
- <?php get_post_mime_type( $ID ) ?>
【参数】
$ID
(整数)(可选)文章ID
默认值:”
返回的值
(布尔型|字符)
返回mime类型,出错时则返回False。
【示例】
- <?php
- $mime_type=get_post_mime_type( 36 );//假设id为36的文章是图片类型是“image/jpeg”
- echo $mime_type;
//打印出image/jpeg
?>
修改记录
自2.0.0版本后
【源文件】
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;
- }