今天给学习WordPress建网站的学员们介绍一个小功能,就是在自己网站文章的底部添加文章字数统计和阅读时间的功能。效果如下图:

这个功能可以统计一篇文章总共有多少字,并且预计文章阅读时间。下面学做网站论坛就来介绍一下制作方法。
//字数和预计阅读时间统计
function count_words_read_time () {
global $post;
$text_num = mb_strlen(preg_replace('/\s/','',html_entity_decode(strip_tags($post->post_content))),'UTF-8');
$read_time = ceil($text_num/400);
$output .= '本文共' . $text_num . '个字,阅读需要' . $read_time . '分钟。';
return $output;
}
<?php echo count_words_read_time(); ?>