4

EE v2.5.3

I'm trying to accomplish the following:

  • 6 Radio Shows (Mon-Fri)
  • 1 Radio Show (Sun)
  • Default Setting (Logo)

I'd like to be able to tell EE the following:

If Monday - Friday AND
0600 - 1000 
Morning Show

else if

1000 - 1500
Midday Show

etc etc..

else if
Sunday AND
0600 - 1200
Sunday Show

else if 
1700-1900
Sunday Night Show

else 
Default display of Logo

My (non-working) Example:

<div id="in_studio_now_content" class="container_4">

{if
    '{current_time format="%l"}' == Thursday AND
    '{current_time format="%H%i"}' >= '1000' AND
    '{current_time format="%H%i"}' <= '1700'
}

<div class="showContainer">
    <img src="http://placehold.it/75x75" class="container_1" />
    <div class="showInfo left">
        <h5>The Midday Show</h5>
    <p>with Jenn</p>
    <p class="timeslot">Weekdays 10:00 - 3:00 pm</p>
        <div id="facebookLike">F like 32k</div>
    </div>
    <a href="#" class="showLink container_3">More about this show &rsaquo;</a>
</div><!-- /show -->

{/if}

</div><!-- studio content -->
Sal B
  • 540
  • 1
  • 5
  • 20

2 Answers2

1

This should sort you

{if
'{current_time format='%l'}' == 'Thursday' &&
'{current_time format='%H%i'}' >= '1000' &&'{current_time format='%H%i'}' <= '1700'}

Note that I've placed Thursday in single quotes and replaced your time formatting with single quotes also.

Steven Grant
  • 1,236
  • 3
  • 15
  • 32
0

I'd recommend using a combination of Switchee and IFElse, both from Croxton, to make this parse more quickly since it's a rather complex conditional. How about something like this, for example?

{exp:switchee var="{current_time format='%l'}" parse="inward"}
    {case value="Monday|Tuesday|Wednesday|Thursday|Friday"}
       {exp:ifelse parse="inward"}
           {if '{current_time format="%H%i"}' >= '0600' AND '{current_time format="%H%i"}' <= '0959'}
               Morning show
           {if:elseif '{current_time format="%H%i"}' >= '1000' AND '{current_time format="%H%i"}' <= '1459'}
               Midday Show
           {/if}
       {/exp:ifelse}
     {/case}
     {case value="Saturday"}
         Do the same sort of thing for Saturday
     {/case}
     {case value="Sunday"}
         Do the same sort of thing for Sunday
     {/case}
{/exp:switchee} 

Also note here that I've adjusted the times by 1 minutes - otherwise, two conditions in the same set (because you are using equal to or less/greater than) could be true at the same time.

Adrian Macneil
  • 13,017
  • 5
  • 57
  • 70
Jean St-Amand
  • 793
  • 5
  • 12
  • This looks logically sound :) I'll have to see about those two extensions you mentioned. Thanks! – Sal B Nov 08 '12 at 20:58
  • Definitely use [Switchee](http://devot-ee.com/add-ons/switchee) or [IfElse](http://devot-ee.com/add-ons/ifelse) for complex conditionals. – Jason Varga Nov 08 '12 at 22:08
  • Switchee and ifelse are both incredibly powerful and logical. Worth using every time! – Jean St-Amand Nov 08 '12 at 22:29
  • We installed those two modules and the sample code above but nothing outputs. – Sal B Nov 21 '12 at 16:29
  • Actually, i have a small error in there - should be exp:switchee variable="" rather than just var="" - will you please give that a try? – Jean St-Amand Nov 21 '12 at 19:07