首先我们先在文章想要显示的地方加上以下代码,一般我们添加在文章的版权部分
有的主题版权部分可能在functions.php中,也可能在footer.php中
一般都在footer.php文件
<p id="time">Yamdr 的站点正在加载数据.....</p>
然后我们在到footer.php文件中添加JS
<script type="text/javascript">
var colorStr="";
var randomArr=['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'];
for(var i=0;i<6;i++){
colorStr+=randomArr[Math.ceil(Math.random()*(15-0)+0)];
}
var now =new Date();
function StorageTime() {
var grt= new Date("03/02/2020 00:00:00");//时间格式:月/日/年 时/分/秒
now.setTime(now.getTime()+250);
years = Math.floor((now - grt ) / 1000 / 60 / 60 / 24 /365);
days = Math.floor((now - grt ) / 1000 / 60 / 60 / 24 - (years * 365));
hours = Math.floor((now - grt ) / 1000 / 60 / 60 - (24 * Math.floor((now - grt ) / 1000 / 60 / 60 / 24)));
if(String(hours).length ==1 ){hours = "0" + hours;}
minutes = Math.floor((now - grt ) / 1000 /60 - (24 * 60 * Math.floor((now - grt ) / 1000 / 60 / 60 / 24)) - (60 * hours));
if(String(minutes).length ==1 ){minutes = "0" + minutes;}
seconds = Math.floor((now - grt ) / 1000 - (24 * 60 * 60 * Math.floor((now - grt ) / 1000 / 60 / 60 / 24)) - (60 * 60 * hours) - (60 * minutes));
if(String(seconds).length ==1 ){seconds = "0" + seconds;}
if(years!=0){var outputtime="本站已安全存活<span>"+years+"</span>年"+"<span>"+days+"</span>天"+"<span>"+hours+"</span>时"+"<span>"+minutes+"</span>分"+"<span>"+seconds+"</span>秒";}else{var outputtime="本站已安全存活<span>"+days+"</span>天"+"<span>"+hours+"</span>时"+"<span>"+minutes+"</span>分"+"<span>"+seconds+"</span>秒";}
document.getElementById("time").style.color="#"+colorStr;
document.getElementById("time").innerHTML = outputtime;
}
setInterval("StorageTime()",250);
</script>
最后在header.php里加个CSS样式就大功告成了
<style>
#time{
text-shadow: 0px 0px 3px blue;
text-align: center;
}
#time span{
color: red;
padding: 0 8px;
}
</style>