在网络上访问别人的博客时,发现了一个不错的设置,在文章页脚添加网页计时,记录博客运行时间。看着时间一秒一秒的叠加,成就感油然而生。于是也想在这个博客添加这个计时器,代码也不难,都是学过的,只要找到对的地方添加就好了。
操作如下:
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> |
更改完成别忘了更新文件,再刷新博客,页脚的运行计时就显示出来了