搜索
查看: 5848|回复: 0

给Typecho添加页面加载时间代码

[复制链接]

714

主题

354

回帖

2669

积分

管理员

本论坛第一帅

积分
2669

热心会员推广达人宣传达人突出贡献优秀版主荣誉管理论坛元老

QQ
发表于 2018-12-31 11:14:43 来自手机 | 显示全部楼层 |阅读模式 来自 甘肃
在主题里的functions.php文件添加下面一段代码
[pre]
  /**
     * 加载时间
     * @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;
    }
[/pre]
然后把加载耗时:<?php echo timer_stop();?>这段代码放到你想要显示的位置。
我由于放到了底部,所以把上面这段代码放到了footer.php里,你们也可以放在其他地方的,不影响最终效果~
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表