这段代码自己添加过,但一直认为不够完美,效果参考本站。代码理论上适用任何类型的站点,可自定义。关于错位问题,我用火狐、IE11,没发现此问题。
添加代码至user-profile.php文件
1、打开主题目录下/inc/user/user-profile.php
文件,查找以下代码(请仔细查找,不要全部复制进行查找,因为格式不同会提示查找不到。)
- <ahref=“#login”class=“flatbtn”id=“login-main”>
- <iclass=“bebe-timerauto”></i>
- <?php_e(‘登录‘,‘begin’);?>
- </a>
- <?php}?>
- </div>
- </div>
2、在上面代码后面添加下面的代码
- <scripttype=“text/javascript”>today=newDate();
- varday;
- vardate;
- varhello;
- hour=newDate().getHours();
- if(hour<6){
- hello=‘凌晨好!‘;
- }elseif(hour<9){
- hello=‘早上好!’;
- }elseif(hour<12){
- hello=‘上午好!’;
- }elseif(hour<14){
- hello=‘中午好!‘;
- }elseif(hour<17){
- hello=‘下午好!‘;
- }elseif(hour<19){
- hello=‘傍晚好!’;
- }elseif(hour<22){
- hello=‘晚上好!‘;
- }else{
- hello=‘夜深了!‘;
- }
- functionGetCookie(sName){
- vararr=document.cookie.match(newRegExp(“(^|)”+sName+“=([^;]*)(;|$)”));
- if(arr!=null){
- returnunescape(arr[2])
- };
- returnnull;
- }
- varGuest_Name=decodeURIComponent(GetCookie(‘author’));
- varwebUrl=webUrl;
- if(Guest_Name!=“null”){
- hello=Guest_Name+‘,‘+hello+‘欢迎回来。’;
- }
- document.write(‘‘+hello);</script>
- <scripttype=“text/javascript”>vard,s=“”;
- varx=newArray(“星期日”,“星期一”,“星期二”,“星期三”,“星期四”,“星期五”,“星期六”);
- d=newDate();
- s+=d.getFullYear()+“年”+(d.getMonth()+1)+“月”+d.getDate()+“日“;
- s+=x[d.getDay()];
- document.writeln(s);</script>
经过上面的步骤,基本功能都已经实现了,保存后刷新站点首页看看是不是有效果^_^

此文已更新,解决一些bug,请看另一篇。
WordPress顶部显示问候语和日期的完美解决方法



