资料来源:
膘叔的实验室 - typecho为文章增加字数统计和计算阅读时长
记录 - Typecho新文章标题添加"New"标签
为文章添加字数统计及阅读时长
有时候看到别人的博客上都有一个当前文章总字数xxxx,阅读时长xx分钟,就想着是不是其实也可以为typecho加一个。看了一下还算简单,因为 $this->content()
,是echo后的输出,但事实上,你也能访问 $this->content
,于是代码就出来了:
总字数:<?php echo mb_strlen($this->content);?>,
阅读时长:<?php echo round(mb_strlen($this->content)/300,1);?>分钟
标题增加new标签
1、在当前主题配置文件Functions.php文件中,在合适的位置加上以下代码:
/**
* 判断时间区间
*
* 使用方法 if(timeZone($this->date->timeStamp)) echo 'ok';
*/
function timeZone($from){
$now = new Typecho_Date(Typecho_Date::gmtTime());
return $now->timeStamp - $from < 24*60*60 ? true : false;
}
2、在需要调用的位置加上以下代码:
<?php if(timeZone($this->date->timeStamp)) echo 'new'; ?>
操作完毕。