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));
    $text = preg_replace("/[^\x{4e00}-\x{9fa5}]/u", "", $rs['text']);
    echo mb_strlen($text,'UTF-8');
}

在需要引用的地方插入如下代码

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

参考自 Destined

返回文章列表 打赏
本页链接的二维码
打赏二维码
期待你的评论