基于时间的条件

时间:2012-11-05 08:25:21

标签: expressionengine

是否可以通过服务器时间在EE中触发条件?

{if servertime == 'midnight to 13:00'}
      do this
{if:else}
      do something else
{/if}

谢谢

4 个答案:

答案 0 :(得分:7)

当然,您可以将{current_time}全局变量用于基本条件。要使用您的示例,以下是我们如何检查时间是在午夜和13:00之间:

{if
    '{current_time format="%H%i"}' >= '0000' AND
    '{current_time format="%H%i"}' <= '1300'
}
    It's between 00:00 and 13:00
{if:else}
    It isn't.
{/if}

答案 1 :(得分:4)

如果你不反对在你的模板中使用一点点php,那么用户指南就有一个基本的例子来帮助你:http://expressionengine.com/user_guide/modules/channel/channel_entries.html#start-on

这个插件http://devot-ee.com/add-ons/cc-time-difference也可以派上用场。

答案 2 :(得分:3)

重申Jean所说的 - 如果你正在做这样的事情,你需要确保你的DST(日间节能)得到适当的配置。

如果您没有使用FocusLab配置 - 只需将以下内容放入config.php(在system / expressionengine / config /中)

 $config['daylight_savings'] = ((bool) date('I')) ? 'y' : 'n';

那将动态地为你排序。

答案 3 :(得分:1)

您还需要观看DST设置。解决这个问题的一种方法是使用FocusLab的Master Config修复它,以便自动处理DST。

相关问题