admin 发表于 2018-12-31 11:14:43

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

在主题里的functions.php文件添加下面一段代码

/**
   * 加载时间
   * @return bool
   */
    function timer_start() {
      global $timestart;
      $mtime   = explode( ' ', microtime() );
      $timestart = $mtime + $mtime;
      return true;
    }
    timer_start();
    function timer_stop( $display = 0, $precision = 3 ) {
      global $timestart, $timeend;
      $mtime   = explode( ' ', microtime() );
      $timeend   = $mtime + $mtime;
      $timetotal = number_format( $timeend - $timestart, $precision );
      $r         = $timetotal < 1 ? $timetotal * 1000 . " ms" : $timetotal . " s";
      if ( $display ) {
            echo $r;
      }
      return $r;
    }

然后把加载耗时:<?php echo timer_stop();?>这段代码放到你想要显示的位置。
我由于放到了底部,所以把上面这段代码放到了footer.php里,你们也可以放在其他地方的,不影响最终效果~
页: [1]
查看完整版本: 给Typecho添加页面加载时间代码