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_excerpt() - 文章是否有自定义摘录 - WordPress函数 - WordPress动力
当前浏览:首页 / WordPress函数 / has_excerpt()

has_excerpt( int|WP_Post $post )

文章是否有自定义摘录


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 2 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 "7daa69091da2c3c5a00b72a3f5f57880" 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

excerpt 摘要more...

has 判断有more...


描述

更多类似的主题函数信息,请查看主题开发手册中的条件标签文章。


参数

$post

(int|WP_Post) (可选) 文章 ID 或WP_Post对象。默认为全局$post。


返回

(bool) 如果文章有自定义摘录,则为True,否则为false。



源码

查看源码 官方文档


更新日志

版本描述
2.3.0开始引入

使用示例

  • 示例1

    当你需要隐藏自动显示的摘录,只显示你的文章摘录。

    if ( ! has_excerpt() ) {
    	echo '';
    } else { 
    	the_excerpt();
    }
    
  • 示例2

    测试文章中是否存在摘录

    // Get $post if you're inside a function.
    global $post;
    
    if ( has_excerpt( $post->ID ) ) {
    	// This post has excerpt.
    } else {
    	// This post has no excerpt.
    }
    
  • 示例3

    用文本或代码替换自动摘录

    <?php if ( ! has_excerpt() ) : ?>
    	<!-- your text or code -->
    <?php endif; ?>