当前浏览:首页 / WordPress函数 / has_post_format()

has_post_format( string|string[] $format = array(), WP_Post|int|null $post = null )

文章是否有给定的格式或任意格式

format 格式

has 判断有more...

postmore...


参数

$format

(string|string[]) (可选) 要检查的一种或多种格式。

默认值: array()

$post

(WP_Post|int|null) (可选) 要检查的文章,默认为循环中的当前文章。

默认值: null


返回

(bool) 如果文章有给定的格式或任意格式(如果没有指定格式的话),则为true,否则为false。


说明

用法:
$format = has_post_format($format, $post_id);


源码

查看源码 官方文档


更新日志

版本描述
3.1.0开始引入

使用示例

  • 示例1

    从Codex迁移的示例:

    <?php
    /*
     * Do something if the post format is a gallery
     */
    
    if ( has_post_format('gallery') ) {
      // Do something
    }
    ?>