导入文章 2024.7.23
This commit is contained in:
1 parent
ccc398bf36
commit
6eff722775
315 files changed
+62489
-330
No files matched your search
@@ -0,0 +1,99 @@
|
||||
---
|
||||
layout: post
|
||||
cid: 15
|
||||
title: Twitter主题加入加载耗时,访问总量功能
|
||||
slug: 2
|
||||
date: 2021-09-01T13:20:00
|
||||
updated: 2021-12-29T16:05:58
|
||||
status: hidden
|
||||
author: 小赵同学
|
||||
categories:
|
||||
- 教程
|
||||
tags:
|
||||
gemini_comment: 这篇教程操作简单,轻松在 Twitter 主题中添加了加载耗时和访问总量小功能。作为一名 Typecho 博客新手,感谢博主的分享,让我了解到这个便捷且实用的方法。现在我的主题界面多了两项有意义的信息,既可以监控网站性能,又可以随时查看博客的受关注程度,真是太棒了!
|
||||
goForward:
|
||||
goForwardLink:
|
||||
location:
|
||||
show_theme: 2
|
||||
showThemeInPost: 0
|
||||
top_img: https://usj.cc/usr/uploads/2021/09/2099879238.jpg
|
||||
---
|
||||
|
||||
|
||||
摸爬滚打,又从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>
|
||||
```
|
||||
感谢您的访问,转载请注明出处
|
||||
|
||||
|
||||
|
||||
[1]: https://usj.cc/usr/uploads/2021/09/925164534.png
|
||||
Reference in new issue
Block a user