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>

更改完成別忘了更新文件,再刷新博客,頁腳的運行計時就顯示出來了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM