Typecho 文章字数统计代码
时间:4年前 阅读:8696
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); ?>
以上代码转自:https://app.typecho.me/coder/64.html
网友评论