Display no time when event is set to "all day"

Home Forums Calendar Products Events Calendar PRO Display no time when event is set to "all day"

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #939729
    Nicola
    Participant

    Hello hello,

    I have replaced

    <?php echo tribe_events_event_schedule_details(); ?>

    with

    <?php echo tribe_get_start_date( $post->ID, false, 'd M Y' ); ?>
    <?php echo tribe_get_start_date( $post->ID, false, 'g:ia' ); ?>

    Now when the event is set to “all day” the time output is 0:00 o’clock. I am looking for a way to change the time output to “all day” or not have it displayed at all.

    Can you help me?
    Kind Regards,
    Nicola

    #939733
    Barry
    Member

    Hi Nicola: you can use tribe_event_is_all_day() to detect if it is an all day event – and show or hide the time information appropriately 🙂

    #939752
    Nicola
    Participant

    Hello, I have tried this, but it does not work. I want to show the time only if it is not an all-day event.

    <?php if ( (tribe_event_is_all_day == false) || ( int $postId = null ) ): ?>
    <?php echo tribe_get_start_date( $post->ID, false, 'G:i' ); ?>
    <?php endif ?>

    I don’t know php so this gives me a syntax error. Can you given me the correct syntax please.

    Kind Regards,
    Nicola

    #939803
    Barry
    Member

    Hi Nicola,

    So to call a function you need to follow the function name with parentheses – so instead of just:

    tribe_event_is_all_day

    Ensure you follow up with ():

    tribe_event_is_all_day()

    You might also want to modify the second part of the if clause — in PHP a single equals sign by itself is used to assign a value rather than to compare it (comparison can be done with a double == or treble === equals signs).

    I definitely appreciate this sort of work can be tricky when you don’t know PHP, but please bear in mind if you decide to make customizations like this it is really your responsibility to understand what’s happening so you can maintain your work going forward – though of course we’re always happy to give you a pointer in the right direction if we can 🙂

    Thanks again and I hope that helps!

    #940056
    Nicola
    Participant

    Hello Barry,
    thank you for your help so far, but I can’t seem to get it to work.

    Trying this code I think it should only proceed if the event is not an all-day event, but instead it does the opposite, it displays only the all-day events.

    <?php if ( tribe_event_is_all_day(false) ): ?>

    Setting it to true does not change this.

    #940097
    Barry
    Member

    Hi there Nicola,

    So I wouldn’t recommend passing in true or false in this situation. Unless you’re calling this function from somewhere unusual you probably need pass in nothing at all:

    if ( tribe_is_all_day_event() ) { /*...*/ }

    It does optionally accept a single parameter, though, which should be the numeric ID of the event you are interested in (though you need only provide this in those rare situations where it isn’t obvious to WordPress/our plugin):

    if ( tribe_is_all_day_event( 12345 ) ) { /*...*/ }

    I hope that clarifies things 🙂

    #942722
    Nicola
    Participant

    Hello, I still cant get it to work. The code you give me assumes that the attribute tribe_is_all_day_event is true and then execudes what is the {} brackets.

    if ( tribe_is_all_day_event( 12345 ) ) { /*...*/ }

    But I would like to execude the code in the {} brackets only if the arguement is not true, if it is not an all-day-event.

    Can you help me?
    Kind reghards,
    Nicola

    #942757
    Barry
    Member

    Hi Nicola!

    So you can do one of at least two things here — either test to see if the response is negative (using the ! operator):

    if ( ! tribe_is_all_day_event( 12345 ) ) { /*...*/ }

    Or use an if/else structure:

    if ( tribe_is_all_day_event( 12345 ) ) { 
        /*...display things one way...*/ 
    } else {
        /*...display things some other way...*/ 
    }

    We’re always happy to try and point people in the right direction but since this is very much customization territory and the remaining stumbling blocks mostly seem to relate to PHP knowledge – and I’m afraid we just don’t have the resources to coach you through that – I’m going to go ahead and close out this topic.

    Of course if any other issues crop up definitely do let us know and we’ll be happy to help as best we can 🙂

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Display no time when event is set to "all day"’ is closed to new replies.