^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助,如果有代码出错,请联系站长解决
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 腾讯云3年2核2G新品轻量限时特惠只需408元

WordPress估计文章阅读时间

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

//估算阅读时间
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 函数的基础知识

2 核 2G 限时特惠 396 元/3 年    宝塔建站 10850 大礼包

赠人玫瑰,手有余香。