Home › Forums › Calendar Products › Events Calendar PRO › Date range
- This topic has 7 replies, 2 voices, and was last updated 11 years, 10 months ago by
Barry.
-
AuthorPosts
-
June 13, 2014 at 9:58 am #223462
dave9621
ParticipantI have an issue with how date ranges are displayed in the events list. I have an event that runs over three days, October 3-5, 2014. But the events list renders that range as “October 3, 2014 – 5”, which is horrible. Is there any way of fixing this, how would we get it to render “October 3-5, 2014”, maybe in a template override or a new function??
June 16, 2014 at 8:55 am #229546Barry
MemberHi – that definitely isn’t ideal, but nor should it display like that out of the box. I see you already ran through the standard recommended troubleshooting steps of deactivating all other plugins and switching to a default, completely unmodified theme. Can you confirm that these steps made no difference to the problem?
Particularly if you might have added snippets to customize the calendar in your theme’s functions.php file it’s well worth running through these steps.
June 16, 2014 at 2:29 pm #230075dave9621
ParticipantHi Barry, thanks for helping me. I deactivated all plugins except for Events Calendar and Events Calendar Pro, no affect. I switched to the 2012 theme and that had no affect, still getting the improper date range. I double checked my functions.php and there is no code in there regarding the dates. I did have it in there at one time before upgrading to 3.6, since 3.6 had the date code fix I needed (adding the year no matter if it’s this year or not) in the settings panel I removed it. I have set in the Events settings for the display of “Date without year” to “F j, Y” this is what’s causing the trouble I think. When I make it “F j” then I get “October 23-26” BUT I need it to be “October 23-26, 2014”, we ALWAYS want the year to appear on our dates. Is there a code for that?
June 17, 2014 at 8:37 pm #232397Barry
MemberBUT I need it to be “October 23-26, 2014″, we ALWAYS want the year to appear on our dates. Is there a code for that?
It’s definitely possible: if you’re familiar with WordPress’s hooks and filters you’ll be happy to know there is a filter for just this sort of purpose:
tribe_events_event_schedule_detailsYour callback could then use tribe_get_start_date() and tribe_get_end_date() to derive the information it needs and build your custom format from there. Does that help?
June 18, 2014 at 12:45 pm #233615dave9621
ParticipantThanks Barry. Any chance you can give me a little more help? If you point me in the right direction I might be able to figure this out. For instance, in my template override I have the date being displayed by this line of code:
<?php echo tribe_events_event_schedule_details(); ?>
Can you give me an example of how to build a callback with the two functions you referenced?June 19, 2014 at 7:16 am #235464Barry
MemberSure thing – a simple example would look a little like this:
add_filter( 'tribe_events_event_schedule_details', 'custom_schedule_details' ); function custom_schedule_details() { return tribe_get_start_date() . ' until ' . tribe_get_end_date(); }Do check out the docs for both of those functions – linked to in my last reply – to see how you can specify other formats (you may also want to check out this guide to PHP date/time formatting).
Good luck 🙂
June 19, 2014 at 6:12 pm #236680dave9621
ParticipantBarry, thanks for the guidance, I finally figured it out. If anyone else is looking for a function that adds the current year and formats the date range if the event is over multiple dates, here’s my code if someone else is looking to solve this issue. Thanks again for you help!
add_filter( ‘tribe_events_event_schedule_details’, ‘custom_schedule_details’ );
function custom_schedule_details() {
/* get the year of the event */
$endYear = tribe_get_end_date($pageID, false,”Y”);
/* get the date of the event, only the number, no month or year */
$endDate = tribe_get_end_date($pageID, false,”j”);
/* find out if the event is more than one day long */
if ($endDate != tribe_get_start_date($pageID, false,”j”)) {
/* if start day and end day are NOT equal then return the date range, including the year */
return tribe_get_start_date($pageID, false,”F j”) . ‘ – ‘ . $endDate . “, ” . $endYear;
} else {
/* if the event is only a single day return the date, including the year */
return tribe_get_start_date($pageID, false,”F j”) . “, ” . $endYear;
}
}June 20, 2014 at 6:23 am #238019Barry
MemberGreat – and thank you for sharing the final solution 🙂
I’ll go ahead and close this thread, but if you have any further questions please do feel free to post new threads as needed. Thanks!
-
AuthorPosts
- The topic ‘Date range’ is closed to new replies.
