博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WordPress页脚添加运行时间显示
阅读量:4493 次
发布时间:2019-06-08

本文共 1800 字,大约阅读时间需要 6 分钟。

在网络上访问别人的博客时,发现了一个不错的设置,在文章页脚添加网页计时,记录博客运行时间。看着时间一秒一秒的叠加,成就感油然而生。于是也想在这个博客添加这个计时器,代码也不难,都是学过的,只要找到对的地方添加就好了。

操作如下:

Wordpress后台——>外观——>编辑——>在右边的主题文件中找到【主题页脚 (footer.php)】修改代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
 
* The template for displaying the footer
 
*
 
* Contains the closing of the "site-content" div and all content after.
 
*
 
* @package WordPress
 
* @subpackage Twenty_Fifteen
 
* @since Twenty Fifteen 1.0
 
*/
?>
    
</div><!-- .site-content -->
    
<footer id=
"colophon"
class
=
"site-footer"
role=
"contentinfo"
>
        
<div
class
=
"site-info"
>
            
托管于腾讯云
            
<?php
                
/**
                 
* Fires before the Twenty Fifteen footer text for footer customization.
                 
*
                 
* @since Twenty Fifteen 1.0
                 
*/
                
do_action(
'twentyfifteen_credits'
);
            
?>
            
<!--以下为计时功能代码-->
            
<script language=
"javascript"
>
            
function
tick() {
                
var
years,days,hours, minutes, seconds;
                
var
openday =
new
Date
(
'2008/01/01 00:00'
);   
//这里填写建站时间
                
var
today =
new
Date
();
//获取系统当前时间
                
var
total = (today.getTime()-openday.getTime())/1000;
                
years=Math.
floor
(total/31536000);
                
total=total-years*31536000;
                
days=Math.
floor
(total/86400);
                
total=total-days*86400;
                
hours=Math.
floor
(total/3600);
                
total=total-hours*3600;
                
minutes=Math.
floor
(total/60);
                
total=total-minutes*60;
                
seconds=Math.
floor
(total);
                
timeString =
"网站运行:"
+years+
"年"
+days+
"天"
+hours+
"时"
+minutes+
"分"
+seconds+
"秒"
;
                
document.getElementById(
"Clock"
).innerHTML = timeString;
                
window.setTimeout(
"tick();"
, 1000);
            
}
            
window.onload = tick;
            
</script>
            
<span id=
"Clock"
></span>
            
<!--以上为计时功能代码-->
        
</div><!-- .site-info -->
    
</footer><!-- .site-footer -->
</div><!-- .site -->
<?php wp_footer(); ?>
</body>
</html>

更改完成别忘了更新文件,再刷新博客,页脚的运行计时就显示出来了

转载于:https://www.cnblogs.com/54xavier/p/8462122.html

你可能感兴趣的文章
编译安装git
查看>>
《Linux内核分析》 第三节 构造一个简单的Linux系统MenuOS
查看>>
RPC是什么?
查看>>
CLR via C#:CLR的执行模型
查看>>
JS获取服务器时间
查看>>
如何对数据排序和拆分文件
查看>>
数据解析01-15
查看>>
linux 安装mysql数据库——yum安装法
查看>>
Several ports (8005, 80, 8009) required by Tomcat v6.0 Server at localhost are already in use
查看>>
事件监听器
查看>>
设计模式之单例设计模式
查看>>
异常的基本概念
查看>>
vue 在发送axios请求时数据渲染问题
查看>>
动态链接库dll
查看>>
2018 Multi-University Training Contest 3 - HDU Contest
查看>>
组合数取模(转载)
查看>>
9.2NOIP模拟题
查看>>
整合SpringDataJpa
查看>>
vue过渡
查看>>
tcpreplay 博客目录
查看>>