惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
Vercel News
Vercel News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
J
Java Code Geeks
M
MIT News - Artificial intelligence
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog RSS Feed
MongoDB | Blog
MongoDB | Blog
G
Google Developers Blog
Engineering at Meta
Engineering at Meta
量子位
S
SegmentFault 最新的问题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
A
About on SuperTechFans
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
Recent Announcements
Recent Announcements
腾讯CDC
I
InfoQ
F
Fortinet All Blogs
Hugging Face - Blog
Hugging Face - Blog
Blog — PlanetScale
Blog — PlanetScale
H
Help Net Security
爱范儿
爱范儿

优世界

OpenWrt 路由器改纯 AP 模式记录(Cudy TR3000 + 中兴 F50) Ubuntu 24.04 安装 Zabbix 8.0 全记录 我的静态博客动态化方案 Claude Code 启动脚本 我的5G路由器方案:中兴F50+cudy tr3000 256MB 还是弃用了使用多年的全拼输入法 临走前一份襄阳牛肉面 EdgeOne Pages 部署 Twikoo 评论 一个朋友圈风格 Hugo 主题 搓了一个仿朋友圈的Hugo主题 一个人烧烤被拒单了 周末闲暇时间翻修了一下博客 我把Vercel换成了EdgeOne Pages 博客友链实时健康监测方案 Artalk评论区接入AI摘要的尝试 给Hugo博客添加瀑布流相册功能 Hugo静态博客如何实现搜索功能 Artalk评论系统实现段落评论功能 为什么我觉得网页昼夜切换那么重要 博客六周年:从折腾到回归平淡 如何hugo静态实现友联朋友圈功能 脂溢性皮炎的烦恼 还是放弃了iPhone16e 米环勿扰同步问题 除草日记 Hugo使用GitHub Action自动刷新多吉云CDN缓存 迁移博客至hugo 添加ikun摆件 parsec远程软件报6023错误 win11右键菜单改回win10方法
Twitter主题加入加载耗时,访问总量功能
2021-09-01 · via 优世界

摸爬滚打,又从WordPress换回typecho了

不得不说typecho轻量,后台速度快

这篇文章就教大家如何给自己的Twitter的主题加两个小功能

分别是加载耗时和访问总量的小功能,先上图

教程开始

首先找到自己主题文件的 functions.php 中加入以下代码

/*
* 加载时间
* @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;}`

这个是加载耗时的代码,下面一并加上访问总量的代码

同样也是加在functions.php 的文件里

    //总访问量
    function theAllViews()
        {
            $db = Typecho_Db::get();
            $row = $db->fetchAll('SELECT SUM(VIEWS) FROM `typecho_contents`');
                echo number_format($row[0]['SUM(VIEWS)']);
        }

由于我使用的是油油作者的Twitter主题,所以我给大家介绍

Twitter主题应该修改那个位置,其他主题请自己调试

首先找到主题目录的important/sidebar.php文件

大概在118行左右你把相应代码加到自己想要加的位置

添加加载耗时功能,请加下面代码在相应位置

<div class="widget-list">加载耗时:<?php echo timer_stop();?></div>

添加访问总量功能,请加下面代码在相应位置

<div class="widget-list">访问总量:<?php echo theAllViews();?>次</div>

感谢您的访问,转载请注明出处