废话不多说,上代码
一、统计文章字数,将以下代码加入到主题的function.php文件中。
// 字数统计
function cnwper_count_words ($text) {
global $post;
if ( '' == $text ) {
$text = $post->post_content;
if (mb_strlen($output, 'UTF-8') < mb_strlen($text, 'UTF-8')) $output .= '<span class="word-count">共' . mb_strlen(preg_replace('/\s/','',html_entity_decode(strip_tags($post->post_content))),'UTF-8') .'字</span>';
return $output;
}
}
前台调用代码
<?php echo cnwper_count_words($text); ?>
二、预估阅读时间,将以下代码加入到主题的function.php文件中。
// 统计预估阅读时间 By itbulu.com
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/300); // 修改数字300调整时间
$output .= '本文共计' . $text_num . '个字,预计阅读时长' . $read_time . '分钟。';
return $output;
}
前台调用代码
<?php echo count_words_read_time(); ?>

528

被折叠的 条评论
为什么被折叠?



