我们经常看到有些网友的Typecho网站底部会有一个加载完成时间,这个虽然用途不大,但是可以看到当前页面的加载速度,比如是否需要调整网站速度。以及对网站进行优化处理。在这篇文章中,我们Typecho主题插件网可以整理出来Typecho主题添加当前页面时间代码,无需使用插件实现。
第一、在当前主题Functions.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;
}

第二、在需要提交的位置
<?php echo timer_stop();?>

在我们需要添加的位置加上代码即可。


扫描二维码,在手机上阅读!