GeekerCode更好的WordPress主题,值得信任的WordPress主题开发商

极美的主题、极致的插件

WordPress文章附件类型判断函数:get_post_mime_type()

摘要:wordpress文章函数:get_post_mime_type()【说明】按ID编号检索附件的mime类型。该函数可用于任何文章类型,但更适用于附件类型。【用法】<?php get_post_mime_type( $ID )

wordpress文章函数:get_post_mime_type()

【说明】

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

【用法】

<?php get_post_mime_type( $ID ) ?>

【参数】

$ID(整数)(可选)文章ID   默认值:”

返回的值(布尔型|字符) 返回mime类型,出错时则返回False。

修改记录:自2.0.0版本后

【示例】

<?php
$mime_type=get_post_mime_type( 36 );//假设id为36的文章是图片类型是“image/jpeg”
echo $mime_type;
//打印出image/jpeg
?>

【源文件】

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;
}

建站!你有充足的理由选择我们

世界上超过30%的网站是由WordPress搭建,而我们是国内最靠谱的WordPress主题开发商
QQ咨询在线咨询问答互助微信号geekercode微信公众号云服务器