子比主题美化:文章页面添加文章字数和阅读时间

Jaysun

温馨提示:这篇文章已超过501天没有更新,请注意相关的内容是否还可用!

主题文章页面顶部显示文章字数和阅读时间,可以让访问者了解阅读需要的时间,个人感觉此功能并不是很实用,另文章字数和阅读时间都不是很准,同时用处也不是很大…喜欢的话自己拿去试试吧!

效果图:

12.jpg

实用教程:

1、在主题目录下functions.php文件把下面的代码添加进去:

//  文章字数和阅读时间
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;
}

2、在主题目录zibll/inc/functions/zib-single.php,把下面代码添加到132行处(如下图)

<!--文章字数和阅读时间--><i class="fa fa-hourglass-start"></i> <?php echo count_words_read_time(); ?>


11.jpg

好了可以看效果了。

您需要 登录账户 后才能发表评论

发表评论

快捷回复: 表情:
AddoilApplauseBadlaughBombCoffeeFabulousFacepalmFecesFrownHeyhaInsidiousKeepFightingNoProbPigHeadShockedSinistersmileSlapSocialSweatTolaughWatermelonWittyWowYeahYellowdog
评论列表 (有 2 条评论,1186人围观)
网友昵称:hostsir
hostsir V 普通用户 Google Chrome 107.0.0.0 Windows 10 x64 沙发
2022-11-24 来自江苏 回复
这个不行了

目录[+]

取消
微信二维码
微信二维码
支付宝二维码