每小时显示一个不同的WordPress(工具集)简码

时间:2019-07-18 13:25:44

标签: javascript php wordpress

我试图每小时在WordPress页面上显示不同的简码(来自Toolset)(访客时间,而不是服务器时间)。我需要根据访问者的HOUR显示另一个字段。

我尝试通过每小时增加一个'else if'并每小时增加我的简码来改编此代码https://www.encodedna.com/javascript/say-good-morning-afternoon-evening-using-javascript.htm,但这只是一个灾难,什么也没显示。

<body>
<label id="hourstory"></label>
</body>

<script>
var myDate = new Date();
var hrs = myDate.getHours();

var story;

if (hrs < 1)
    story = '[types field='stime0001'][/types]';
else if (hrs >= 1 && hrs <= 2)
    story = '[types field='stime0102'][/types]';
else if (hrs >= 2 && hrs <= 3)
    story = '[types field='stime0203'][/types]';
else if (hrs >= 3 && hrs <= 4)
    story = '[types field='stime0304'][/types]';
else if (hrs >= 4 && hrs <= 5)
    story = '[types field='stime0405'][/types]';
else if (hrs >= 5 && hrs <= 6)
    story = '[types field='stime0506'][/types]';
else if (hrs >= 6 && hrs <= 7)
    story = '[types field='stime0607'][/types]';
else if (hrs >= 7 && hrs <= 8)
    story = '[types field='stime0708'][/types]';
else if (hrs >= 8 && hrs <= 9)
    story = '[types field='stime0809'][/types]';
else if (hrs >= 9 && hrs <= 10)
    story = '[types field='stime0910'][/types]';
else if (hrs >= 10 && hrs <= 11)
    story = '[types field='stime1011'][/types]';
else if (hrs >= 11 && hrs <= 12)
    story = '[types field='stime1112'][/types]';
else if (hrs >= 12 && hrs <= 13)
    story = '[types field='stime1213'][/types]';
else if (hrs >= 13 && hrs <= 14)
    story = '[types field='stime1314'][/types]';
else if (hrs >= 14 && hrs <= 15)
    story = '[types field='stime1415'][/types]';
else if (hrs >= 15 && hrs <= 16)
    story = '[types field='stime1516'][/types]';
else if (hrs >= 16 && hrs <= 17)
    story = '[types field='stime1617'][/types]';
else if (hrs >= 17 && hrs <= 18)
    story = '[types field='stime1718'][/types]';
else if (hrs >= 18 && hrs <= 19)
    story = '[types field='stime1819'][/types]';
else if (hrs >= 19 && hrs <= 20)
    story = '[types field='stime1920'][/types]';
else if (hrs >= 20 && hrs <= 21)
    story = '[types field='stime2021'][/types]';
else if (hrs >= 21 && hrs <= 22)
    story = '[types field='stime2122'][/types]';
else if (hrs >= 22 && hrs <= 23)
    story = '[types field='stime2223'][/types]';
else if (hrs >= 23 && hrs <= 24)
    story = '[types field='stime2324'][/types]';


document.getElementById('hourstory').innerHTML =
    '<hr>' + story + '<hr>';
</script> 

我希望在晚上11点有(例如)[types field ='stime2324'] [/ types]输出...但它只是空白。

0 个答案:

没有答案