Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #5705
    EsansB
    Participant

    Hello again & thanks for your help !

    I tried to remove the time of the events in a event list displayed in a sidebar, but unsuccessfully.
    I understand it’s a part of the function displayed the order of the events, but my client really insists.

    So is there a way to do that only for the event list widget ?

    Thanx again !

    #5706
    Bartosz
    Keymaster

    There are multiple ways, but since v 1.2.0 it’s as easy as pasting this to your theme functions.php file:

    // Removing Events Maker template actions
    function df_remove_em_template_actions() {
    	remove_action('em_before_widget_event_title', 'em_display_widget_event_date', 10);
    }
    add_action('wp', 'df_remove_em_template_actions');

    Hope this helps.

    #5707
    EsansB
    Participant

    Thanx for your reactivity !
    But my client actually wants to display only the date, but not the time in the list.
    With you code the all date, with the time is gone !

    #5708
    Bartosz
    Keymaster

    Then use that pluggable function in functions.php and adjust the date format:

    function em_display_widget_event_date()
    { 
    	// display event date
    	em_display_event_date('', $args = array('format' => ''));
    }

    You’ll find the details in includes/core-functions.php

    #5709
    EsansB
    Participant

    Sorry but I’m not sure how to do that ?

    #5710
    Bartosz
    Keymaster

    Did you look at the em_display_event_date function in plugin code?

    #5730
    EsansB
    Participant

    Hello !
    So I create the function em_display_widget_event_date, here is the code :

     <?php /* Display event date widget*/
    if (!function_exists('em_display_widget_event_date'))
    {
    	function em_display_widget_event_date($format = '', $args = array())
    	{
    		global $post;
    		
    		$date 			= em_get_the_date($post->ID, array('format' => array('date' => 'm/d/y')));
    		$all_day_event 	= em_is_all_day($post->ID);
    		$html			= '';
    		
    		// default args
    		$defaults = array(
    			'separator' => ' - ',
    			'format' => 'link',
    			'before' => '',
    			'after' => '',
    			'show_author_link' => false,
    			'echo' => true
    		);
    		$args = apply_filters('em_display_event_date_args', wp_parse_args($args, $defaults));
    		
    		// date format options
    		$date_format = array('date' => 'j/m/y');
    		
    
    		
    		// is all day
    		if($all_day_event && !empty($date['start']) && !empty($date['end']))
    		{
    			// format date (date only)
    			$date['start'] = em_format_date($date['start'], 'date', $date_format);
    			$date['end'] = em_format_date($date['end'], 'date', $date_format);
    	
    			// one day only
    			if($date['start'] === $date['end'])
    			{
    				$date_output = $date['start'];
    			}
    			// more than one day
    			else
    			{
    				$date_output = implode(' '.$args['separator'].' ', $date); 
    			}
    		}
    		// is not all day, one day, different hours
    		// C EST ICI QUE COMMENCE LA GALERE !!!!!!!
    		elseif(!$all_day_event && !empty($date['start']) && !empty($date['end']))
    		{
    			// one day only
    			if(em_format_date($date['start'], 'date') === em_format_date($date['end'], 'date'))
    			{
    				$date_output = em_format_date($date['start'], 'date', $date_format); 
    			}
    			// more than one day
    			else
    			{
    				$date_output = em_format_date($date['start'], 'date', $date_format) . ' ' . $args['separator'] . ' ' . em_format_date($date['start'], 'date', $date_format); 
    			}
    		}
    		// any other case
    		else 
    		{		
    			$date_output = em_format_date($date['start'], 'date', $date_format) . ' ' . $args['separator'] . ' ' . em_format_date($date['end'], 'date', $date_format);  
    		}
    		
    		// generate output
    		$html .= $args['before'];
    		
    		// output format
    		if ($args['format'] == 'link')
    			$html .= sprintf('<span class="entry-date date"><a href="%1$s" rel="bookmark"><abbr class="dtstart" title="%2$s"></abbr><abbr class="dtend" title="%3$s"></abbr>%4$s</a></span>',
    				esc_url(get_permalink()),
    				esc_attr($date['start']),
    				esc_attr($date['end']),
    				esc_html($date_output)
    			);
    		else
    			$html .= sprintf('<span class="entry-date date"><abbr class="dtstart" title="%1$s"></abbr><abbr class="dtend" title="%2$s"></abbr>%3$s</span>',
    				esc_attr($date['start']),
    				esc_attr($date['end']),
    				esc_html($date_output)
    			);
    		
    		
    		$html .= $args['after'];
    		
    		$html = apply_filters('em_display_event_date', $html);
    		
    		if ($args['echo'] === true)
    			echo $html;
    		else
    			return $html;
    		
    	}
    }
    ?>

    The result is :
    – The time disapearred (that’s what I wanted)
    – The all days events are displayed like : “start date – end date”, which is perfect,
    – BUT the events with multiple occurrences only shows the first start date.
    > I wish I can get this : start date 1, start date 2, start date 3, etc.

    Can you please tell me what’s wrong in this code ?

    Really thank you again !

    #5731
    Bartosz
    Keymaster

    Oh, you don’t need all that. Pleasy try:

    function em_display_widget_event_date()
    { 
    	// display event date
    	em_display_event_date(array('date' => 'j/m/y', 'time' => ' '));
    }
    
    #5732
    Bartosz
    Keymaster

    I missed your occurrences question:

    It will not work like this out of the box. By default event occurences show up as single events in events list, in archive and widget.

    However in this case you could try the em_get_occurrences() function, located in core-functions.php.

    #5736
    EsansB
    Participant
    This reply has been marked as private.
    #5743
    Bartosz
    Keymaster

    You have to disable Show occurences in widget settings first.

    And then replace the function above with that:

    function em_display_widget_event_date()
    { 
    	// display event date
    	em_display_event_occurrences(array('date' => 'j/m/y', 'time' => ' '));
    }

    I’m not sure if it works like, because this is intended to be used inside single event page. If it doesn’t you’ll have to use em_get_occurrences() function directly.

    function em_display_widget_event_date()
    { 
    	// get the occurrences
    	$occurrences = em_get_occurrences($post->ID);
    	// loop the result
    	foreach ($occurrences as $occurrence) {
    		// do sometching with it, for example display the formated start date
    	}
    }
Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.