[Plugin: The Events Calendar] Getting "This event has passed." to show
-
This is my first post on the entire WordPress forum, so I hope I’m submitting this info correctly.
The “single.php” view template has a line of code that’s supposed to indicate that the displayed event is in the past:
<?php if (the_event_end_date() > time() ) { ?><small><?php _e('This event has passed.', $spEvents->pluginDomain) ?></small> <?php } ?>
I’ve found a few apparent problems with this:
- First, the data type for ‘the_event_end_date()’ and ‘time()’ seem to be different, so it’s never compared correctly.
- Second, even if they were the same data type, the direction of the “>” sign is wrong. It should be “<“, indicating the current time must be later than the end date for the message to be displayed.
- Finally, to get TEC to hide the event end time, I will give my event an end time that is before the event start time. Thus, it is possible with this code (if it was working correctly) that the event still hasn’t started yet, but will say that it’s over.
To fix this, I made the following change:
<?php if ( ( strtotime(the_event_start_date()) < time() ) && ( strtotime(the_event_end_date()) < time() ) ) { ?> <?php _e( 'This event has passed.', $spEvents->pluginDomain) ?> <?php } ?>
I used the strtotime() function to get the data into the correct datatype. Also, time() must now be after both the event start and end time before the message will be displayed.
One lingering problem with this message is that it’s displayed next to the iCal button, which doesn’t really make sense. So one final change I did was to relocate the code to within the “Start:”, “End:” and “Cost:” <dl> Definition List. This meant a few <dt> and <dd> tags needed to be added too. My new code for the section looks like this:
<dl class="column"> <dt><?php _e('Start:', $spEvents->pluginDomain) ?></dt> <dd><?php echo the_event_start_date(); ?></dd> <?php if (the_event_start_date() !== the_event_end_date() ) { ?> <dt><?php _e('End:', $spEvents->pluginDomain) ?></dt> <dd><?php echo the_event_end_date(); ?></dd> <?php } ?> <strong><?php if ( ( strtotime(the_event_start_date()) < time() ) && ( strtotime(the_event_end_date()) < time() ) ) { ?> <?php _e( '<dt></dt><dd><em>(This event has passed.)</em></dd> <br />', $spEvents->pluginDomain) ?> <?php } ?></strong> <?php if ( the_event_cost() ) : ?> <dt><?php _e('Cost:', $spEvents->pluginDomain) ?></dt> <dd><?php echo the_event_cost(); ?></dd> <?php endif; ?> </dl>
- The topic ‘[Plugin: The Events Calendar] Getting "This event has passed." to show’ is closed to new replies.