搜索内容 · 精彩近在咫尺!
highlight_off 关闭
Typecho实现页面加载时间
鼠子
bookmark 共87字

大家可能注意到MioMoe主题底部和HTML注释中有一个页面加载时间:
QQ_1720659264394.png
QQ_1720659305068.png

实现功能

添加代码

在主题文件functions.php文件中添加代码:

/**
 * 加载时间
 * Blog.MioMoe.Cn
 */
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;
}

QQ_1720659426925.png

实现引用

选一个适合的地方引入代码

页面加载时间<?php echo timer_stop();?>

如果是注释的方式就使用

<!-- 页面加载时间<?php echo timer_stop();?> -->

QQ_1720659512284.png

版权声明: 本站文章大部分始于原创,用于个人学习记录,可能对您有所帮助,仅供参考!
comment 暂无评论

暂时还没评论呢~ 快去抢沙发吧!

account_circle
email
link