WordPress函数has_post_format()通过ID判断文章是否有指定的类型

描述:

通过ID判断文章是否有指定的类型

用法:

<?php $format = has_post_format($format,$post_id); ?>

参数:

$format

(string|array) (必填) 文章形式的名称或文章形式的名称数组。

默认值: none

$post_id

(integer) (可选) 文章ID

默认值: 当前文章ID

示例:

<?php 
if (has_post_format('image')) { 
echo '这篇文章的形式为“图像”'; 
}?>

源文件:

function has_post_format( $format = array(), $post = null ) {
    $prefixed = array();
 
    if ( $format ) {
        foreach ( (array) $format as $single ) {
            $prefixed[] = 'post-format-' . sanitize_key( $single );
        }
    }
 
    return has_term( $prefixed, 'post_format', $post );
}