Remove End Date if same as Start Date

Home Forums Calendar Products Events Calendar PRO Remove End Date if same as Start Date

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #46228
    chirocare
    Participant

    Hello, we are wondering if there is a way to hide the end date if it is the same as the start date. Right now, it looks like this:
    ——————
    Start: May 11, 2013 8:00 am
    End: May 11, 2013 12:00 pm
    ——————
    Ideally, if the start and end date are the same, it could look like this:
    ——————
    Date: May 11, 2013
    Time: 8:00 am – 12:00 pm
    ——————
    Is there any way around this via the interface or do we have to make custom template adjustments? It does seem a little bit redundant to have the date twice — my guess is most people would prefer the suggested alternative. Thoughts?

    Thanks.

    #46231
    chirocare
    Participant

    I looked in the list.php template, where I see this is outputted… and there is a conditional for

    My events are not set to be all day events, but somehow they are getting stuck in this conditional. Any ideas why?

    #46233
    chirocare
    Participant

    Oops, the code didn’t come through on that last one. I was trying to show:
    —–
    if (tribe_is_multiday() || !tribe_get_all_day()):
    —–
    Both of these are outputting nothing (i.e. not true), so the second condition is what is catching us here. If I remove this, it displays (for the event I’m looking at now):
    ———–
    Date: April 27, 2013 8:00 am
    ———–
    However, now we are missing the end time. Thoughts?

    #46235
    Barry
    Member

    Hi chirocare. Just because I’d like to be sure I’m not missing anything from your explanation, can you share the amended code using Pastebin, Gist or a similar service (and paste the link in here)?

    #46237
    chirocare
    Participant

    All right, I made some changes to my list.php and single.php templates. I don’t really like modifying the templates if I can help it, but it seems like this may be the way to do here.
    In list.php:
    —————
    + Removed the “|| !tribe_get_all_day()” from the conditional on line 51
    + Changed the date display to “tribe_get_start_date($post->ID,false)” so that it only shows the date.
    + Added another table row for “Time:” and used this to output just the start and end times: “echo tribe_get_start_date($post->ID,true,’ ‘) . ” – ” . tribe_get_end_date($post->ID,true,’ ‘);”
    —————
    On single.php, I made similar changes. However, one thing of note was that the conditional was checking if tribe_get_start_date() equaled tribe_get_end_date(). This would only be true if we didn’t set an end time. But we want people to know how long the event is. So I replaced the conditional with what I have now in list.php, which is “tribe_is_multiday().”

    Modern Tribe folks, if you see anything amiss here or if you think we’ll run into issues, please let me know.
    Thanks, C

    #46240
    chirocare
    Participant

    Sure. We must have been responding at the same time. Here’s a Gist. https://gist.github.com/relish27/5414230#file-list_and_single-php
    Let me know what you think.

    #46243
    Barry
    Member

    OK – as it happens Jonah (also on the support team) saw this thread and was about to jump in with an answer which I’ll relay to you now. His idea was to replace lines 51-65 in list.php with this code – does that help here?

    #46251
    chirocare
    Participant

    Well, not exactly. When I output tribe_is_multiday() and tribe_get_all_day(), they both returned nothing (or not true). Therefore, I’d still get caught in your new conditional #2 — tribe_is_multiday() || !tribe_get_all_day() — which is what the first conditional was before. And, in your third conditional case (the “else”), which is where I want to end up, it still only shows the start time. I want it to show the date and the time range.

    #46274
    Barry
    Member

    Sure ok, so I’ve used the concept you posted initially as my template here:

    Ideally, if the start and end date are the same, it could look like this:
    ——————
    Date: May 11, 2013
    Time: 8:00 am – 12:00 pm
    ——————

    And came up with this code which you could use to generate something close to the above. There are some cases it doesn’t work well with, such as a multiday event – consider an event starting today and ending in a couple of days, starting at 7pm and ending at 9am. It renders like this:

    Date: April 18, 2013 – April 20, 2013
    Time: 7.00pm – 9.00am

    However that might not be an issue in your case. I also stripped out some of the event schema markup, simply because I wasn’t 100% sure that this sort of configuration would work well with it, however you can test and adjust as needed.

    #46449
    chirocare
    Participant

    This reply is private.

    #46644
    Barry
    Member

    Well, I mean this is basically the realms of custom development so we can offer pointers but it’s ultimately up to you to build the solution you’re after here 🙂

    Certainly if you prefer the way multiday events are handled in your own snippet then it makes sense to use that or, if you want a fusion of the two, then you’ll need to do a little more work on it.

    I don’t think there’s too much more we can do here to help though so unless you’ve go further questions I’m inclined to close this ticket. Thanks!

    #46649
    chirocare
    Participant

    Yes, by all means — feel free to close it. Thanks for your help!

    #46651
    Barry
    Member

    Great!

Viewing 13 posts - 1 through 13 (of 13 total)
  • The topic ‘Remove End Date if same as Start Date’ is closed to new replies.