2026-01-30 21:11:05 +08:00
|
|
|
---
|
2026-01-20 21:13:24 +08:00
|
|
|
pid: 34
|
2024-07-23 13:47:57 +08:00
|
|
|
layout: post
|
|
|
|
|
cid: 15
|
|
|
|
|
title: Twitter主题加入加载耗时,访问总量功能
|
2026-03-01 11:48:36 +08:00
|
|
|
slug: 20210901
|
2026-01-30 21:11:05 +08:00
|
|
|
date: 2021-09-01T13:20:00.000Z
|
|
|
|
|
updated: 2021-12-29T16:05:58.000Z
|
2026-01-22 21:26:48 +08:00
|
|
|
draft: false
|
2024-07-23 13:47:57 +08:00
|
|
|
author: 小赵同学
|
2026-01-30 21:11:05 +08:00
|
|
|
categories:
|
2024-07-23 13:47:57 +08:00
|
|
|
- 教程
|
2026-01-30 21:11:05 +08:00
|
|
|
tags: null
|
|
|
|
|
gemini_comment: >-
|
|
|
|
|
这篇教程操作简单,轻松在 Twitter 主题中添加了加载耗时和访问总量小功能。作为一名 Typecho
|
|
|
|
|
博客新手,感谢博主的分享,让我了解到这个便捷且实用的方法。现在我的主题界面多了两项有意义的信息,既可以监控网站性能,又可以随时查看博客的受关注程度,真是太棒了!
|
|
|
|
|
goForward: null
|
|
|
|
|
goForwardLink: null
|
|
|
|
|
location: null
|
2024-07-23 13:47:57 +08:00
|
|
|
show_theme: 2
|
|
|
|
|
showThemeInPost: 0
|
2026-01-30 21:11:05 +08:00
|
|
|
top_img: 'https://usj.cc/usr/uploads/2021/09/2099879238.jpg'
|
|
|
|
|
ai_comment: >-
|
|
|
|
|
哈哈,技术博主反复横跳的样子像极了换手机壳的我!Typecho确实像穿了运动鞋的WordPress,跑起来带风。这个计时器代码很实用,不过看到SQL查询时默默备份了下数据库——毕竟我的博客访问量可能还没我家猫的粉丝多。期待下次折腾教程!
|
2024-07-23 13:47:57 +08:00
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
摸爬滚打,又从WordPress换回typecho了
|
|
|
|
|
|
|
|
|
|
不得不说typecho轻量,后台速度快
|
|
|
|
|
|
|
|
|
|
这篇文章就教大家如何给自己的Twitter的主题加两个小功能
|
|
|
|
|
|
|
|
|
|
分别是加载耗时和访问总量的小功能,先上图
|
|
|
|
|
|
|
|
|
|
![][1]
|
|
|
|
|
|
|
|
|
|
教程开始
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
首先找到自己主题文件的 functions.php 中加入以下代码
|
|
|
|
|
|
|
|
|
|
```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 的文件里
|
|
|
|
|
|
|
|
|
|
```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行左右你把相应代码加到自己想要加的位置
|
|
|
|
|
|
|
|
|
|
添加加载耗时功能,请加下面代码在相应位置
|
|
|
|
|
|
|
|
|
|
```php
|
|
|
|
|
<div class="widget-list">加载耗时:<?php echo timer_stop();?></div>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
添加访问总量功能,请加下面代码在相应位置
|
|
|
|
|
|
|
|
|
|
```php
|
|
|
|
|
<div class="widget-list">访问总量:<?php echo theAllViews();?>次</div>
|
|
|
|
|
```
|
|
|
|
|
感谢您的访问,转载请注明出处
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-01-23 20:38:35 +08:00
|
|
|
[1]: 925164534.png
|
2026-01-22 21:26:48 +08:00
|
|
|
|