首先在functions.php中添加如下代码:
function count_words($str){
$words = 0;
$str = eregi_replace(" +", " ", $str);
$array = explode(" ", $str);
for($i=0;$i < count($array);$i++)
{
if (eregi("[0-9A-Za-zÀ-ÖØ-öø-ÿ]", $array[$i]))
$words++;
}
return $words;
}
然后在single.php中希望显示字数统计的位置加上:
Word count: <?php echo count_words($post->post_content); ?>
大功告成!
原文:How to get words count of your post?
分类:新闻资讯