前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >typecho博客handsome主题博客信息添加访客数量和网站响应耗时

typecho博客handsome主题博客信息添加访客数量和网站响应耗时

原创
作者头像
小唐同学.
发布2022-02-18 11:25:33
1.4K0
发布2022-02-18 11:25:33
举报
文章被收录于专栏:CMS建站教程

首先将以下代码加到themes/handsome/libs/Content.php中放在class Content{}之前

代码语言:php
复制
/_访问总量_/

function theAllViews(){

$db = Typecho\_Db::get();

$row = $db->fetchAll('SELECT SUM(VIEWS) FROM `typecho_contents`');

echo number\_format($row0);

}

/_响应时间_/

function timer\_start() {

global $timestart;

$mtime = explode( ' ', microtime()  );

$timestart = $mtime1 + $mtime0;

return true; 

}

timer\_start();

function timer\_stop( $display = 0, $precision = 3  ) {

global $timestart, $timeend;

$mtime = explode( ' ', microtime()  );

$timeend = $mtime1 + $mtime0;

$timetotal = number\_format( $timeend - $timestart, $precision  );

$r = $timetotal < 1 ? $timetotal \* 1000 . " ms" : $timetotal . " s";

if ( $display  ) {

echo $r;

}

return $r;

}

然后在/usr/themes/handsome/component/sidebar.php文件内,找到博客信息下面添加以下代码

代码语言:html
复制
<li class="list-group-item text-second"> <span class="blog-info-icons"> <i data-feather="users"></i></span>
<span class="badge
pull-right"><?php echo theAllViews();?></span><?php _me("访客总数") ?></li>
<li class="list-group-item text-second"> <span class="blog-info-icons"> <i data-feather="refresh-ccw"></i></span>
<span class="badge
pull-right"><?php echo timer_stop();?></span><?php _me("响应耗时") ?></li>

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档