详情页

帝国CMS根据内容正文字段[newstext]批量获取描述简介字段[smalltext]的方法

时间:2023年12月24日

编辑:佚名

帝国CMS已经发布的信息,我想批量的根据新闻正文重新获取简介应该怎么处理?
最好能定义获取多少字符,方便重新整理简介
功能要求:批量从信息的新闻正文字段里获取自定字数的文字到简介字段!
解决方案
一、首先重新按需设置自动生成简介的字数,帝国CMS默认自动获取简介的字数可以从下图方式更改,
我这里为了方便演示改成了320,默认为160,这里的数字,2个字符代表一个汉字,一个字符为一个英文。

这步做完,新发的信息,默认截取简介字数就变成了新设置的字数了!已经发布的信息的处理方法请继续往下看!
二、写一个处理PHP,名字叫auto_smalltext.php,懒得写的,后面提供了下载地址了,直接下载使用也可以。
PHP的内容:
点击复制代码 PHP
<?php
define('EmpireCMSAdmin','1');
require("../class/connect.php");
require("../class/db_sql.php");
require("../class/functions.php");
require("../class/t_functions.php");
require("../data/dbcache/class.php");
require("../data/language/gb/pub/fun.php");
$link=db_connect();
$empire=new mysqlquery();
$tbname='news';//数据表名称
$quantity=320;//重新生成简介字数:320代表320个英文,160个汉字!
$query="select * from {$dbtbpre}ecms_".$tbname." order by id desc";
$sql=$empire->query($query);
while($r=$empire->fetch($sql))
{
$rb=$empire->fetch1("select newstext from {$dbtbpre}ecms_".$tbname."_data_".$r[stb]." where id='".$r[id]."' limit 1");
$newstext=$rb[newstext];
$smalltext=strip_tags($newstext);
$smalltext=esub($smalltext,$quantity);
$empire->query("update {$dbtbpre}ecms_".$tbname." set smalltext='$smalltext' where id='$r[id]'");
}
echo '执行完毕';
db_close();
$empire=null;
?>
把PHP放到/e/extend/ 目录下新建auto_smalltext.php!
三、按需调整PHP文件里的数据表名字和简介字数。
四、备份你的数据库,防止出错.
五、浏览器运行  你的域名/e/extend/auto_smalltext.php
完成!
相关文章
猜你需要