首页 > SEO优化 > Typecho 文章字数统计代码

Typecho 文章字数统计代码

时间:2023年10月21日 分类:SEO优化 浏览量:68

Typecho 文章字数统计代码

Typecho做模板的时候如果显示出来文章内有多少字数是不是比较高大上。反正我是这么认为的

在functions.php中写入代码:

function  art_count ($cid){
$db=Typecho_Db::get ();
$rs=$db->fetchRow ($db->select ('table.contents.text')->from ('table.contents')->where ('table.contents.cid=?',$cid)->order ('table.contents.cid',Typecho_Db::SORT_ASC)->limit (1));
echo mb_strlen($rs['text'], 'UTF-8');
}

在模板中调用:

<?php echo art_count($this->cid); ?>

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

标签: