开往   虫洞   统计
  • 文章总数:218 篇
  • 评论总数:583 条
  • 分类总数:7 个
  • 最后更新:6小时前

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

本文阅读 1 分钟
首页 建站代码 正文

请输入图片描述
给Typecho添加页面加载时间代码

[tip type="share"]第一、代码部分[/tip]

    /**
    * 加载时间
    * @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文件中。
[tip type="share"]第二、调出代码[/tip]

    加载耗时:<?php echo timer_stop();?>

这段代码放到你想要显示的位置。
我由于放到了底部,所以把上面这段代码放到了footer.php里,你们也可以放在其他地方的,不影响最终效果~

[colour type=" red"]最新测试 typecho 1.2 用下面的代码 [/colour]

[cid="1940"]

本文来自投稿,不代表本站立场,如若转载,请注明出处:
-- 展开阅读全文 --
网页时间格式PHP
« 上一篇 08-01
Typecho 调用热门文章
下一篇 » 08-02

发表评论

发表评论
    请配置好页面缩略名选项

标签TAG