
给Typecho添加页面加载时间代码
第一、代码部分
- /**
- * 加载时间
- * @return bool
- */
- 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;
- }
将代码加到当前Typecho主题的Functions.php文件中。
第二、调出代码
- 加载耗时:<?php echo timer_stop();?>
这段代码放到你想要显示的位置。
我由于放到了底部,所以把上面这段代码放到了footer.php里,你们也可以放在其他地方的,不影响最终效果~
最新测试 typecho 1.2 用下面的代码
[cid="1940"]
本文来自投稿,不代表本站立场,如若转载,请注明出处: