添加站点访问量代码
首先在 Typecho 后台外观选择编辑当前外观 functions.php 中,添加以下统计代码
注:示例为本博客使用的 handsome 主题,其它主题也可以自行调用,也可以加到libs/Content.php class Content{ 这一行代码的上面
//总访问量
function theAllViews()
{
$db = Typecho_Db::get();
$row = $db->fetchAll('SELECT SUM(VIEWS) FROM `typecho_contents`');
echo number_format($row[0]['SUM(VIEWS)']);
}
添加后点击保存即可;
然后在你需要显示的位置(如:footer.php sidebar.php 等)插入以下调用代码
handsome 主题添加代码位置在:网站根目录/usr/themes/handsome/component/sidebar.php
handsome主题下代码
<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("访客总数") ?>
添加站点加载速度
同样的,在 Typecho 后台外观选择编辑当前外观 functions.php 中,添加以下统计代码
注:示例为本博客使用的 handsome 主题,其它主题也可以自行调用,也可以加到libs/Content.php class Content{
这一行代码的上面
//加载耗时
function timer_start() {
global $timestart;
$mtime = explode( ' ', microtime() );
$timestart = $mtime[1] + $mtime[0];
return true;
}
timer_start();
function timer_stop( $display = 0, $precision = 3 ) {
global $timestart, $timeend;
$mtime = explode( ' ', microtime() );
$timeend = $mtime[1] + $mtime[0];
$timetotal = number_format( $timeend - $timestart, $precision );
$r = $timetotal < 1 ? $timetotal * 1000 . " ms" : $timetotal . " s";
if ( $display ) {
echo $r;
}
return $r;
}
添加后点击保存即可;
然后在你需要显示的位置(如:footer.php sidebar.php 等)插入以下调用代码
handsome 主题添加代码位置在:网站根目录/usr/themes/handsome/component/sidebar.php
<li class="list-group-item"> <i class="glyphicon glyphicon-time text-muted"></i> <span class="badge
pull-right"><?php echo timer_stop();?></span><?php _me("加载耗时") ?></li>
欢迎给我留言评论或关注公众号哦~
订阅我的公众号,扫描二维码或微信搜索【 比邻之地 】我会定期发布教程和分享,有问题欢迎留言,感谢你的关注!本文作者:若无特殊说明,则本文为原创文章,版权归上官大吉所有
本文链接:http://91guangju.com/index.php/archives/36/
版权说明:所有原创文章采用知识共享署名-非商业性使用4.0国际许可协议进行许可,经许可转载和修改,请务必注明文章来源且不可用于商业目的