wordpress程序给主题页脚添加网站运行时长显示

2020年1月2日14:00:06来源:星光博客 评论 119
声明, 本站以知更鸟主题begin建站,所有代码均支持begin主题,如使用其他主题,请自行修改插入位置即可。

一、打开 footer.php ,将代码添加到 </div><!-- .site-info --> 上面。

<!--页脚运行时长开始--> 
Theme by <a rel="external nofollow" target="_blank" href="https://www.ls102.com/wp-content/themes/begin/go.php?url=aHR0cDovL3ptaW5nY3guY29t" target="_blank" rel="nofollow noopener" marked="1">知更鸟</a> · 托管于 <a rel="external nofollow" target="_blank" href="https://www.ls102.com/wp-content/themes/begin/go.php?url=aHR0cHM6Ly93d3cuYWxpeXVuLmNvbQ==" target="_blank" rel="nofollow noopener" marked="1">阿里云</a> · 网站已运行:<span id="htmer_time" style="color: #0196e3;"></span>
<script>
function secondToDate(second) {
if (!second) {
return 0;
}
var time = new Array(0, 0, 0, 0, 0);
if (second >= 365 * 24 * 3600) {
time[0] = parseInt(second / (365 * 24 * 3600));
second %= 365 * 24 * 3600;
}
if (second >= 24 * 3600) {
time[1] = parseInt(second / (24 * 3600));
second %= 24 * 3600;
}
if (second >= 3600) {
time[2] = parseInt(second / 3600);
second %= 3600;
}
if (second >= 60) {
time[3] = parseInt(second / 60);
second %= 60;
}
if (second > 0) {
time[4] = second;
}
return time;
}
</script>
<script type="text/javascript" language="javascript">
function setTime() {
var create_time = Math.round(new Date(Date.UTC(2019, 01, 01, 0, 0, 1)).getTime() / 1000);
var timestamp = Math.round((new Date().getTime() + 8 * 60 * 60 * 1000) / 1000);
currentTime = secondToDate((timestamp - create_time));
currentTimeHtml = currentTime[0] + '年' + currentTime[1] + '天'
+ currentTime[2] + '时' + currentTime[3] + '分' + currentTime[4]
+ '秒';
document.getElementById("htmer_time").innerHTML = currentTimeHtml;
}
setInterval(setTime, 1000);
</script>
<!--结束-->

注:其中,(Date.UTC(2020, 01, 01, 0, 0, 1)) 为建站日期与时间,根据需要自行修改。

二、具体效果图演示,请查看本站页角

OPS技术联盟 https://www.ls102.com

  • 客服微信
  • 微信扫一扫
  • weinxin
  • 微信公众号
  • OPS技术联盟,每天掌握一个小知识!
  • weinxin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: