访客统计

  1. handsome/libs/Content.php 文件里添加以下统计代码
//总访问量
php function theAllViews() { $db = Typecho_Db::get(); 
$row = $db->fetchAll('SELECT SUM(VIEWS) FROM `typecho_contents`'); 
echo number_format($row[0]['SUM(VIEWS)']); }
  1. handsome/component/sidebar.php 添加显示代码
<li class="list-group-item text-second">
    <i class="glyphicon glyphicon-user text-muted"></i>
    <span class="badge pull-right"><?php echo theAllViews();?></span>
<?php _me("访客总数") ?>
</li>

加载耗时

  1. handsome/libs/Content.php 文件里添加以下统计代码
//加载耗时
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;
}
  1. handsome/component/sidebar.php 添加显示代码
<li class="list-group-item text-second"> 
    <i class="glyphicon glyphicon-time text-muted"></i> 
    <span class="badge pull-right"><?php echo timer_stop();?></span>
    <?php _me("加载耗时") ?>
</li>
抛砖引玉,请说出你的见解