1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Is this possible with a <Xen IF>? Message displayed based on day

Discussion in 'XenForo Questions and Support' started by DaveL, Aug 24, 2011.

  1. DaveL

    DaveL Well-Known Member

    Is there an <if> command I could use to have different text displayed depending on the day of the week?

    Eg:

    <if Monday>
    Hello its Monday </if>
    <if Tuesday>
    Hello its Tuesday</if>

    If that is possible, Is it possible to break it down even further, is there an <if> command for time of day?

    Eg:
    <if 0800-1100>
    Good Morning!</if>
    <if 1100-1300>
    Its Lunchtime!</if>

    I used something similar many years ago n vbulletin, however it was built into a skin I purchased so cant go back and look at the code.

    Fingers crossed it will be possible!

    Dave
     
  2. Edrondol

    Edrondol Well-Known Member

  3. Edrondol

    Edrondol Well-Known Member

    Ooh! Maybe not. Looking at the video I don't see the day of the week as an option.
     
  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Hours of the day (specify the range in 24 hour format, in this example between 8:00 and 20:00):

    Code:
    <xen:if is="{xen:time $serverTime, 'G'} >= 8 AND {xen:time $serverTime, 'G'} < 20">
    	MESSAGE
    </xen:if>
    
    Day of the week (0 for Sunday through 6 for Saturday):

    Code:
    <xen:if is="{xen:time $serverTime, 'w'} == 0">
    	MESSAGE
    </xen:if>
    
    For reference, this uses PHP's date() parameters:

    http://us2.php.net/manual/en/function.date.php
     
    Veer, Fuhrmann, Mopquill and 3 others like this.
  5. Edrondol

    Edrondol Well-Known Member

    Where would you put this code and would it have to be re-added each time an upgrade was done?

    edit: I see what you mean. This has nothing to do with Notices. This is for normal text. Very odd.
     
  6. DaveL

    DaveL Well-Known Member

    Hi Jake,

    Many thanks for that (y)

    Ive just tried using the days of the week, but for some reason nothing seems to be showing up. This is the code im using

    HTML:
    <div class="section">
    <div class="secondaryContent id="Html">
    <h3>Playing Today on DCR</h3>
    
    <div class="messageText ugc baseHtml">
     
    <xen:if is="{xen:time $serverTime, 'w'} == 3">
        <strong>Wednesday</strong>
    <p>6am to 7pm - DCR Non-Stop<br />
    7pm to 8pm - Steve Banks<br />
    8pm to 9pm - Albert Thorp's Meaningful Request Show<br />
    9pm to 6am - DCR Non-Stop<br /></p>
    
    </xen:if>
     
        </div>
        </div>
    </div>
    And this is what is displayed:
    today.png

    I dont suppose you can see from the code where abouts im going wrong can you?

    Thanks again, Really appreciated

    Dave
     
  7. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Upon further testing this is not working for me. For some reason all numeric 'day of week' parameters aren't working. Maybe it's my server. Here is an alternative that works for me:

    Code:
    <xen:if is="{xen:time $serverTime, 'D'} == 'Wed'">
    	MESSAGE
    </xen:if>
    
     
    DaveL likes this.
  8. DaveL

    DaveL Well-Known Member

    Thanks Jake, Thats worked great, so is the time one :) Really appreciate that.

    One last question, for the times, is it possible to use minutes as well as hours - Eg 19:30 - 20:15?

    Thanks again
    Dave
     
  9. James

    James Well-Known Member

    If I'm following, you should be able to use:
    Code:
    {xen:time $serverTime, 'G:i:s'}
    Which should return a time based on HH:MM:SS
     
    DaveL likes this.
  10. DaveL

    DaveL Well-Known Member

    Just having a little play and wanted to make sure im using the code the best way. The intention of the above is only display "Test" if it is Wednesday and its between 7pm and 8pm - Is this the best way to do it or should I use two IFs, one for date and one for time?

    EDIT - Got it figured out!

     
    dieketzer likes this.
  11. DaveL

    DaveL Well-Known Member

    What should I use for midnight?

    Would the above work?
     
  12. James

    James Well-Known Member

    Technically there is no "24" in a 24 hour clock. It's 00 - 23, so you'd probably use:
    Code:
    <xen:if is="{xen:time $serverTime, 'G'} = 00">
    // code
    </xen:if>
    
     
    DaveL likes this.
  13. DaveL

    DaveL Well-Known Member

    Ok, thanks James.

    One final question, I think I may need to use the below piece of code

    And it seems to work, however its also displaying some of the code in the output. Have I joined the time and day parts together correctly?
     
  14. James

    James Well-Known Member

    What part is it displaying in the output?
     
  15. Brogan

    Brogan XenForo Moderator Staff Member

    You have "> after 20.
     
    DaveL likes this.
  16. DaveL

    DaveL Well-Known Member

    Thanks Brogan, that sorted it out :)

    Will having these conditionals cause many problems, such as slow down etc?

    I will to start with be having aprox 4 per day listed.
     
  17. Brogan

    Brogan XenForo Moderator Staff Member

    They're inconsequential in the grand scheme of things so I wouldn't worry about them.
     
    DaveL likes this.
  18. DaveL

    DaveL Well-Known Member

    The answer I was really hoping for! Thanks Brogan :)

    And thank you to everyone else who has helped out in this thread. Really appreciated and hopefully others will find it useful as well.
     
  19. DaveL

    DaveL Well-Known Member

    Hi James,

    I had it working great using whole hours (19,20,21,22 etc) but today was the first time ive tried to add minutes.

    When I added this:
    xenforo pops up the following error when I try to save:

    Line 7 relates to the first line in the top quote.

    Any help really appreciated.
     
  20. James

    James Well-Known Member

    Put it in quotes:
    Code:
    {xen:time $serverTime, 'G:i'} < '19:30'
     
    DaveL likes this.

Share This Page