
內容簡介
喜歡這個外掛嗎?請考慮留下評論或寫下你在網站上使用它的經驗–如果你這樣做,請給我一個連結。
這個外掛在 GitHub 維護,歡迎使用存儲庫報告問題,提交功能請求和拉取請求。
此外掛提供了短代码,讓你可以在指定的日期和時間顯示或隱藏內容。你也可以結合這兩個動作,在一個時間顯示一些內容,然後在另一個時間隱藏它。
如果你想要重複一個日程以顯示和隱藏內容,也有另外一個短碼 –例如只在廣播節目時顯示有關該節目的資訊。
用法 – 單次使用
要在某個時刻顯示或隱藏內容,你可以使用[time-restrict]短碼。例如:
[time-restrict off="2015-01-01"]請參加我們的比賽[/time-restrict]
[time-restrict on="2015-01-01"]抱歉,這項比賽已經結束了[/time-restrict]
如果你在日期中沒有輸入時間,它會預設為 00:00:00,因此在上面的例子中,第一條消息將顯示到 2015-01-01 00:00:00(即在 2015 年的第一秒之前),而第二條消息則會在 2015-01-01 00:00:00(即在 2015 年的第一秒之後)顯示。
你可以使用任何日期或時間字符串,支援 PHP,例如:
[time-restrict off="September 10th, 2014"]將顯示至 09/10/2014[/time-restrict]
[time-restrict off="2014-09-10"]將顯示至 09/10/2014[/time-restrict]
[time-restrict off="10-Septmber 2014"]將顯示至 09/10/2014[/time-restrict]
[time-restrict on="2014/09/10 18:00:00"]將在 09/10/2014 的晚上 6 時後顯示[/time-restrict]
你也可以結合開始和結束日期顯示相同的內容。因此,如果你想讓一些內容在一月1日至一月10日之間顯示,可以這樣做:
[time-restrict on="2015-01-01" off="2015-01-11"]
這是有限時促銷
[/time-restrict]
用法 – 重複日程
要在重複日程上顯示和隱藏內容,可以使用[time-restrict-repeat]短碼。你可以選擇每天、每週、每月或每年。
每天日程的形式如下:
[time-restrict-repeat type="daily" ontime="09:00:00" offtime="17:00:00"]
從 9 到 5 工作
[/time-restrict-repeat]
請注意,你也可以跨越午夜,所以如果你只想顯示從晚上10點到早上5點的內容,可以使用:
[time-restrict-repeat type="daily" ontime="22:00:00" offtime="05:00:00"]
獻給夜貓族
[/time-restrict-repeat]
每週日程的形式如下:
[time-restrict-repeat type="weekly" onday="Monday" offday="Friday"]
工作一周
[/time-restrict-repeat]
如果需要,你可以指定開始和結束時間(如果不指定,它將假設從00:00:00開始,到23:59:59 結束):
[time-restrict-repeat type="weekly" onday="Friday" offday="Monday" ontime="17:00:00" offtime="08:00:00"]
外掛標籤
開發者團隊
原文外掛簡介
Like this plugin? Consider leaving a quick review or writing about how you’ve used it on your site – send me a link to that write up if you do.
This plugin is maintained on GitHub, so feel free to use the repository for reporting issues, submitting feature requests and submitting pull requests.
This plugin provides shortcodes allowing you to display content or hide content at given dates and times. You can also combine the two to show some content at a given time, and then hide it at another time.
There’s also a separate shortcode if you want to repeat a schedule for showing and hiding content – for example to only show information about a radio show while it’s on air.
Usage – single use
To show or hide content at one point in time, you can use the [time-restrict] shortcode. For example:
[time-restrict off="2015-01-01"]Please enter our competition[/time-restrict]
[time-restrict on="2015-01-01"]Sorry, this competition has closed[/time-restrict]
If you do not enter a time with the date, it will default to 00:00:00, so in the above example, the first message will show up until 2015-01-01 00:00:00 (i.e. until the first second of 2015) and the second message will show up from 2015-01-01 00:00:00 (i.e. from the first second of 2015)
You can use any date or time string supported by PHP, such as:
[time-restrict off="September 10th, 2014"]Will display until 09/10/2014[/time-restrict]
[time-restrict off="2014-09-10"]Will display until 09/10/2014[/time-restrict]
[time-restrict off="10-Septmber 2014"]Will display until 09/10/2014[/time-restrict]
[time-restrict on="2014/09/10 18:00:00"]Will show after 09/10/2014 at 6pm[/time-restrict]
You can also combine starting and ending dates for the same piece of content. So if you want some content to appear between January 1st and January 10th, you could do the following:
[time-restrict on="2015-01-01" off="2015-01-11"]
This is a limited time offer
[/time-restrict]
Usage – repeating schedule
To show and hide content on a recurring schedule, you can use the [time-restrict-repeat] shortcode. Your options are a daily, weekly, monthly or annual schedule.
A daily schedule takes the following form:
[time-restrict-repeat type="daily" ontime="09:00:00" offtime="17:00:00"]
Working 9 to 5
[/time-restrict-repeat]
Note that you can also cross over midnight, so to only show something from 10PM to 5AM, you can use:
[time-restrict-repeat type="daily" ontime="22:00:00" offtime="05:00:00"]
For the night owls
[/time-restrict-repeat]
A weekly schedule takes the following form:
[time-restrict-repeat type="weekly" onday="Monday" offday="Friday"]
The work week
[/time-restrict-repeat]
You can also specify start and stop times if you want (it will assume starting at 00:00:00 and ending at 23:59:59 if these are left out, like above):
[time-restrict-repeat type="weekly" onday="Friday" offday="Monday" ontime="17:00:00" offtime="08:00:00"]
It's the weekend baby!
[/time-restrict-repeat]
A monthly schedule takes the following form:
[time-restrict-repeat type="monthly" ondate="01" offdate="07"]
The first week of the month
[/time-restrict-repeat]
You can both cross over the end of the month, and apply times to your start and end dates, e.g.
[time-restrict-repeat type="monthly" ondate="25" offdate="05" ontime="17:00:00" offtime="08:00:00"]
We are exceptionally busy at the end of each billing cycle. Please bear with us!
[/time-restrict-repeat]
And lastly, an annual schedule takes the following form:
[time-restrict-repeat type="annually" onmonth="June" offmonth="August" ondate="01" offdate="31"]
I'm currently in the mountains enjoying the summer!
[/time-restrict-repeat]
You can cross over the end of the month or even the end of the year, and apply times to your start and end dates, e.g.
[time-restrict-repeat type="annually" onmonth="December" ondate="24" offmonth="January" offdate="05" ontime="17:00:00" offtime="08:00:00"]
Our employees are currently enjoying time with their families for Christmas. We'll be back after the New Year.
[/time-restrict-repeat]
If you’re feeling creative, you can even nest shortcodes to account for multiple concurrent conditions. Since you cannot nest shortcodes with the same name, you need to add -2 or -3 to time-restrict-repeat in your shortcode (e.g. [time-restrict-repeat-2]).
For example, showing a message during business hours only on Monday to Friday:
[time-restrict-repeat type="daily" ontime="08:00:00" offtime="17:00:00"]
[time-restrict-repeat-2 type="weekly" onday="Monday" offday="Friday"]
Our store is currently open
[/time-restrict-repeat-2]
[/time-restrict-repeat]
You can also define a message which should appear if your content is not showing by using the else attribute @since 2.5. For example, you could invite people to visit your store during opening hours and ask them come back soon otherwise, like this:
[time-restrict-repeat type="daily" ontime="08:00:00" offtime="17:00:00" else="We're currently closed. Come back and see us when we're open."]
[time-restrict-repeat-2 type="weekly" onday="Monday" offday="Friday" else="We're currently closed. Come back and see us when we're open."]
Our store is currently open
[/time-restrict-repeat-2]
[/time-restrict-repeat]
Note that with nested shortcodes, you need to add the else attribute to each shortcode.
Things to bear in mind
The time used by the plugin is your site’s local time (check in Settings > General).
The else attribute does accept HTML, but is restricted by WordPress’ limitation on HTML inside shortcode attributes.
I also run Do It With WordPress, which has an array of tutorials for managing, modifying and maintaining your WordPress sites, as well as The WP Butler, a service for keeping your site maintained, backed up, updated and secure.
