VPS参考、测评、推荐
分享你关注的VPS主机优惠信息

为wordpress主题添加字数和阅读时间(WordPress主题)

为wordpress主题添加字数和阅读时间(WordPress主题)

为wordpress主题添加字数和阅读时间(WordPress主题)显示字数和阅读时间。不功能是什么,有说人。能不能加一个,然后再加?有这篇主题增加了字数和阅读时间。

具体也分享到这里:

文章字数//字数统计函数zm _ count _ words($ text){ _ strlen (preg _ replace (‘/s/’,’ ‘),html _ entity _ decode(strip _ tags($Post -> Post _ content)),’ UTF -8 ‘)。单词

文章阅读时间//阅读时间函数zm _ get _ reading _ time($ content){ $ zm _ format = ‘

调用文章字数和阅读时间显示文章字数:

& lt?PHP echo zm _ count _ words($ text);?& gt显示阅读时间代码:

& lt?PHP zm _ reading _ time();?& gt将上面的调用代码添加到当前模板的适当位置。

但是字数和阅读时间都不是很准确,尤其是阅读时间,更是扯淡。默认情况下,它是根据CCTV广播员的速度设置的。

写完这篇文章,发现网上有更简洁的代码。的是上面的代码精确到秒,下面的代码只估算到分钟。

函数count _ words _ read _ time(){ $ post;$ text _ num = _ strlen(preg _ replace(‘/s/’,’ ‘),html _ entity _ decode(strip _ tags($ post -& gt;post_content))),’ ut F-8 ‘);$ read _ time = ceil($ text _ num/300);//修改数字300来调整time $output。= ‘本文共有’。$text_num。单词,预计阅读时间为。$read_time。几分钟,”;返回$ output}通话代码:

& lt?PHP echo count _ words _ read _ time();?& gt源代码未知。

:为wordpress主题添加字数和阅读时间(WordPress主题) https://vps.caogenba../92296.html

赞(0) 打赏
未经允许不得转载:草根吧VPS_最新VPS信息参考 » 为wordpress主题添加字数和阅读时间(WordPress主题)
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址