皮皮社
记录生活中的点点滴滴
typecho统计博客所有文章的字数

typecho统计博客所有文章的字数

在你当前主题的functions.php文件中添加函数,
如下:

//字数统计
function allOfCharacters() {
    $chars = 0;
    $db = Typecho_Db::get();
    $select = $db ->select('text')->from('table.contents');
    $rows = $db->fetchAll($select);
    foreach ($rows as $row) { $chars += mb_strlen(trim($row['text']), 'UTF-8'); }
    $unit = '';
    if($chars >= 10000)     { $chars /= 10000; $unit = 'w'; } 
    else if($chars >= 1000) { $chars /= 1000;  $unit = 'k'; }
    $out = sprintf('%.2lf %s',$chars, $unit);
    return $out;
}

然后在底部页面模板中添加:

 <div class="item " style="margin:0 0 0 10px">
 <span> 全站字数 <?php  echo allOfCharacters(); ?>字</span>
    </div>

根据个人爱好添加到自己喜欢的地方就好,小站就添加在侧栏,效果请看左侧。

[ 最后修改于: 2024年09月03日 17:43 ]
打赏
喜欢就打赏一点
微信扫一扫给皮皮个惊喜
微信
分享
文章来源: 部分内容可能来源于公共网络,仅供学习交流,如有侵权,请联系博主进行核实删除。
评论: 0 | 查看: 125
发表评论
隐私评论

湘ICP备2024058534号-1 湘公网安备43110002000102
©2024 PIPISHE Sitemap
暗黑切换