简介
了解查询次数、执行时间、内存占用,对于我们优化博客速度起到很关键的作用,今天就来说下如何在博客页脚中添加这些信息。
具体步骤
首先需要改写主题的functions.php文件,在末尾处加入如下代码:
//显示时间 function performance( $visible = false ) { $stat = sprintf( '%d queries in %.3f seconds, using %.2fMB memory', get_num_queries(), timer_stop( 0, 3 ), memory_get_peak_usage() / 1024 / 1024 ); echo $visible ? $stat : "<!-- {$stat} -->" ; } //显示时间
接下来是如何在前端显示了,找到footer.php后,在前添加如下的代码:
<div id=birdteam><?php if(function_exists('performance')) performance(ture) ;?></div>
这时博客页脚即可显示相关信息,如果对出现的位置不太满意,希望可以居中,可以使用博客样式。
添加如下代码到style.css的末尾处:
/** 时间样式 **/ #birdteam{margin:0px auto; 10px no-repeat #fff;border:1px solid #D7D8DF;padding:10px;width:378px;} /** 样式结束 **/