WordPress估计文章阅读时间

Author: 陌小雨Date: 2015-11-06View: 0

有时候我们需要给来访的人一个提醒,告诉他阅读这篇文章大概需要多长时间,可以用到下面代码:

//估算阅读时间
function count_words () {  
    global $post;  
    $text = $post->post_content;  
    if (mb_strlen($output, 'UTF-8') < mb_strlen($text, 'UTF-8')) $output .= mb_strlen(preg_replace('/\s/','',html_entity_decode(strip_tags($post->post_content))),'UTF-8');  
    return $output;   
}   
function read_time( $return = false) {  
    $wordcount = round(count_words(), -2);  
    $minutes = ceil($wordcount / 300);  
      
    if ($wordcount <= 150) {  
        $output = '预计阅读时间:1分钟';  
    } else {  
    $output = '预计阅读时间:'.$minutes.'分钟';  
} 
echo $output;  
}

怎么调用?不用陌小雨博客教你吧?你需要了解一点php函数的基础知识