Typecho 网站总访客数以及页面加载总耗时代码 | 您所在的位置:网站首页 › html页面加载耗时代码 › Typecho 网站总访客数以及页面加载总耗时代码 |
很过同学在访问其他博客的时候,他们都有页面总访客还有页面加载总耗时的统计代码,那这个功能该如何实现呢? 本文以handsome主题配置为例。 打开Typecho的后台管理页面选择控制台 - 外观 - 编辑当前外观 - 选择模板文件:"functions_mine.php" 写入以下代码: // ... 省略其他代码 //总访问量 function theAllViews() { $db = Typecho_Db::get(); $row = $db->fetchAll('SELECT SUM(VIEWS) FROM `typecho_contents`'); echo number_format($row[0]['SUM(VIEWS)']); } //加载耗时 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; }编辑模块组件文件定义好方法之后,现在需要打开模块组件,文件目录为:\usr\themes\handsome\component\sidebar.php (这个文件是侧边栏组件),滑动至100行左右,添加如下代码即可: 运行效果最终的效果图如下所示: 分享结束~ |
CopyRight 2018-2019 实验室设备网 版权所有 |