首先在 Typecho 后台外观选择编辑当前外观 functions.php 中,添加以下统计代码

注:示例为本博客使用的 handsome 主题,其它主题也可以自行调用

//总访问量
    function theAllViews()
        {
            $db = Typecho_Db::get();
            $row = $db->fetchAll('SELECT SUM(VIEWS) FROM `typecho_contents`');
                echo number_format($row[0]['SUM(VIEWS)']);
        }

添加后点击保存即可;

示例图:
1.png

然后在你需要显示的位置(如:footer.php sidebar.php 等)插入以下调用代码

handsome 主题添加代码位置在:网站根目录/usr/themes/handsome/component/sidebar.php

<li class="list-group-item"> <i class="glyphicon glyphicon-user text-muted"></i> <span class="badge
pull-right"><?php echo theAllViews();?></span><?php _me("访客总数") ?></li>

其他主题单独调用

<?php echo theAllViews();?></span><?php _me("访客总数") ?>

示例图:

2.png

handsome 主题,实际效果示例:

3.png
OK,弄好了,有人问这有什么用?嗯~~好像没什么用,看看也是不错的,哈哈~

Last modification:December 29, 2021
If you think my article is useful to you, please feel free to appreciate