WordPress获取文章内容摘要的方法

2019-10-30,,,,

本文实例讲述了WordPress获取文章内容摘要的方法。分享给大家供大家参考。具体如下:

第一个函数是讲述了可以获取所有文章内容摘要,另一个是在首页只显示第一个记录的文章内容摘要.

这个是我自己写的获取文章内容摘要程序,代码如下:

复制代码代码如下:<?php
global $more;
$more = 1; //1=全文 0=摘要
$my_content = strip_tags(get_the_excerpt(), $post->post_content); //获得文章
$my_content = str_replace(array("rn", "r", "n", " ", "t", "o", "x0B","""),"",$my_content); //删除空格等 如果 不想删除请直接吧这行前面 加上//
$my_content = mb_strimwidth($my_content, 0, 500,"..." ); //摘要前500字节
if (mb_strlen($my_content,'utf-8') < 10){ echo "对不起没有摘要"; } //少于10字节提示语言
else echo $my_content;
?>
首页第一篇显示全文,其他显示摘要,内容输出部分改成以下代码:

复制代码代码如下:if(!$first){
$first = 1;
$more = 1;
the_content();
$more = 0;
}
else {
the_excerpt(); //或者使用the_content();
}

希望本文所述对大家的WordPress建站有所帮助。

《WordPress获取文章内容摘要的方法.doc》

下载本文的Word格式文档,以方便收藏与打印。