Events Manager
[resolved] How to remove redundant Month/Year in multi-day events (4 posts)

  1. jbx
    Posted 2 years ago #

    I am using the the #_EVENTDATES placeholder in my template to display single or multi-day event dates respectively.
    Is there any way to detect that an event's month and year is the same and eliminate them?

    I am getting this: 03 DEC 2012 - 09 DEC 2012
    While ideally I would get this: 03 - 09 DEC 2012

    If it spans over the end of a month however I would ideally get: 25 NOV - 03 DEC 2012

    Is there any way I can go about this?


  2. agelonwl
    Posted 2 years ago #

  3. jbx
    Posted 2 years ago #

    Thanks for that!

    This is the code I actually used, in case anyone else is looking for it. It checks if the year is the same before omitting it, and then checks if the month is the same before omitting it. If the day is also the same it does nothing because EM already works perfectly in that case.

    function my_em_placeholder_mod($replace, $EM_Event, $result)
    	if ( $result == '#_EVENTDATES' )
    		$day_start = date_i18n('d', $EM_Event->start);
    		$day_end = date_i18n('d', $EM_Event->end);
    		if ($day_start != $day_end)
    			$date_format_start = 'd';
    			$year_start = date_i18n('Y', $EM_Event->start);
    			$year_end = date_i18n('Y', $EM_Event->end);
    			if ($year_start != $year_end)
    				$date_format_start .= ' M Y';
    				$month_start = date_i18n('M', $EM_Event->start);
    				$month_end = date_i18n('M', $EM_Event->end);
    				if ($month_start != $month_end)
    					$date_format_start .= ' M';
    			$replace = date_i18n($date_format_start, $EM_Event->start). ' - ' . date_i18n('d M Y', $EM_Event->end);
    	return $replace;
  4. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 2 years ago #

    thx, the first snippet I've added to the upcoming snippets section we're making :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Events Manager
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic