Typecho Word Count

Nexmoe February 18, 2017
This article is an AI translation and may contain semantic inaccuracies.

Super simple. Just insert the following code into functions.php in the root of the current theme.

Currently it only counts Chinese characters in the post.

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');
}

Insert this where you want to display it:

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