wordpress调用文章摘要 判断摘要方法

2023年9月4日11:06:15 发表评论
微信搜一搜 ts小陈

函数名称:has_excerpt

函数介绍:has_excerpt函数用于检查当前文章是否有摘要(excerpt)

wordpress调用文章摘要 判断摘要方法

该函数可以用于判断当前文章是否有摘要,从而在主题开发中根据是否有摘要来进行不同的显示或处理。

示例一:

当前文章有摘要则输出,没有则截取文章内容

  1. <?php if (has_excerpt()) {
  2.                 the_excerpt();   //文章编辑中的摘要
  3.             }else {
  4.                 echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 170,"……");
  5. //文章编辑中若无摘要,自动截取文章内容字数做为摘要,0表示开始的位置,170表示结束的位置
  6. } ?>

示例二:

文章没有摘要的时候,显示空内容

  1. <?php if ( ! has_excerpt() ) {
  2.       echo ' ';
  3. else {
  4.       the_excerpt();
  5. }

 

小陈号卡
ts小陈

发表评论(不允许含有网址!)

:?: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :cry: :mrgreen: :neutral: :razz:

已登录用户不需要填写以下内容