为博客添加恋爱天数小工具

效果预览

扒自Shawn在售的主题超级漂亮!!喜欢的可以去看看。

使用方法.

在wordpress后台 外观-小工具 添加自定义html即可

/*代码中的时间需提前一个月*/


functionsetTime(){varcreate_time=Math.round(newDate(Date.UTC(2018,10,26,6,45,0)).getTime()/1000);vartimestamp=Math.round((newDate().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;}functionsecondToDate(second){if(!second){return0;}vartime=newArray(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;}returntime;}setInterval(setTime,1000);


无法插入wordpress小工具 提示错误,由于主题不同的原因,直接插入或多或少都有可能出现问题,我们可以围魏救赵嵌入解决

在服务器上创建一个html文件

把上边的代码放到创建的html文件里

在小工具里放入下面的代码

Select Code

Copy

这样我的小工具就直接调用的是上边的html网页,等于小工具嵌入网页

#2019-6-16更新


闪电图标换成了爱心图标,效果如下:

代码如下:

/*代码中的时间需提前一个月*/

.widget_text.aplayer{margin:-12px -16px}.widget_text.aplayer.aplayer-info{padding:7px7px7px10px}.widget_text.aplayer.aplayer-info.aplayer-music{margin:0013px0}.giligili-item{position:relative;width:100%;background:#fff;border-radius:4px;overflow:hidden;/*margin-bottom: 8px;*//*阴影*/padding:12px16px;-webkit-box-shadow:01px3pxrgba(26,26,26,.1);box-shadow:01px3pxrgba(26,26,26,.1)}

functionsetTime(){varcreate_time=Math.round(newDate(Date.UTC(2018,10,26,6,45,0)).getTime()/1000);vartimestamp=Math.round((newDate().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;}functionsecondToDate(second){if(!second){return0;}vartime=newArray(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;}returntime;}setInterval(setTime,1000);


文章源自钻芒博客

原文地址:https://www.zmki.cn/3454.html

你可能感兴趣的:(为博客添加恋爱天数小工具)