函数名称:has_excerpt
函数介绍:has_excerpt函数用于检查当前文章是否有摘要(excerpt)
该函数可以用于判断当前文章是否有摘要,从而在主题开发中根据是否有摘要来进行不同的显示或处理。
示例一:
当前文章有摘要则输出,没有则截取文章内容
- <?php if (has_excerpt()) {
- the_excerpt(); //文章编辑中的摘要
- }else {
- echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 170,"……");
- //文章编辑中若无摘要,自动截取文章内容字数做为摘要,0表示开始的位置,170表示结束的位置
- } ?>
示例二:
文章没有摘要的时候,显示空内容
- <?php if ( ! has_excerpt() ) {
- echo ' ';
- } else {
- the_excerpt();
- }