Warning: Trying to access array offset on false in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 216
has_post_format() - 文章是否有给定的格式或任意格式 - WordPress函数 - WordPress动力
当前浏览:首页 / WordPress函数 / has_post_format()

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

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


Warning: Undefined array key -1 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 185

Warning: Undefined array key 3 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 186

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "fbd33194a5ce13c433ddeb80052c4cdc" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "68cbf86a6adef9731b41f24cf8261f7c" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "c662a3ca6b84e8f01cc3765430bbe052" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

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