WordPress页脚添加运行时间显示

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

操作如下:
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

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值