I’m trying to conditionally display an ‘Open’ or ‘Closed’ status on my website using hours vs. current time. I can’t seem to get the code to work. Any suggestions?
{hours}
{if
'{hours:open format="%H%i"}' <= '{current_time format="%H%i"}' &&
'{hours:close format="%H%i"}' > '{current_time format="%H%i"}' &&
'{hours:day}' == '{current_time format="%l"}' && '{hours:open_closed}' != 'Closed'
}
<span class="label pull-right">OPEN</span>
{/if}
{if
'{current_time format="%H%i"}' <= '{hours:open format="%H%i"}' &&
'{current_time format="%H%i"}' > '{hours:close format="%H%i"}' &&
'{hours:day}' == '{current_time format="%l"}' && '{hours:open_closed}' != 'Closed'
}
<span class="label pull-right">CLOSED</span>
{/if}
{hours}(Edit 1 : went ahead and actually tried all this, so the following does work)
Assuming that you have an Hours Channel as follows:
day_of_week: text input; lowercase name of the day (monday, tuesday, etc.) (don’t use “{day}” because that’s an EE expression) open: text input; HHmm in military time format close: text input; HHmm in military time format
Here’s how I’d do it:
{exp:channel:entries channel="hours" search:day_of_week="{current_time format="%l"}" limit="1"}
{if
{current_time format="%H%i"} >= {open} &&
{current_time format="%H%i"} <= {close}
}
<span class="store-availability">OPEN</span>
{if:else}
<span class="store-availability">CLOSED</span>
{/if}
{/exp:channel:entries}Edit 2: There is no need for a open/closed signifier for the day itself. Just enter times that can never be true in the conditional. For example if closed Sunday:
day_of_week: sunday
open: 2399
close: 0001Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.