WordPress

推荐列表 站点导航

当前位置:首页 > 建站教程 > WordPress >

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

来源:网络整理  作者:  发布时间:2020-12-17 21:38
本文实例讲述了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获取文章内容摘要的方法介绍 (https://www.wpmee.com/) WordPress使用教程 第1张

相关热词: 方法

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/jz/wp/4950.shtml

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

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

2020-12-17 编辑:

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

<?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获取文章内容摘要的方法介绍 (https://www.wpmee.com/) WordPress使用教程 第1张

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/jz/wp/4950.shtml

相关文章

风云图片

推荐阅读

返回WordPress频道首页