Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #4798
    Kuba S
    Participant

    Hi
    I found this solution useful when I required to target styling precisely for particular events in FullCalendar view;
    this is a ready-to-take mod rather than a feature request , yet it would be nice to see it in the upcoming update.

    So, in events-maker\includes\shortcodes.php I amended this function a bit:

    function get_calendar_events($args)
    	{
    		$events = em_get_events($args);
    		$calendar = array();
    
    		if(empty($events))
    			return $calendar;
    
    		foreach($events as $event)
    		{
    			$id = $event->ID;
    // mod start
    			$catClasses = array();
    			$aCategories = wp_get_post_terms(  $event->ID, 'event-category');
    			$aTags = wp_get_post_terms(  $event->ID, 'event-tag');
    			
    			if (count($aCategories))
    				foreach($aCategories as $category) {
    					$catClasses[] = "fc-event-cat-" . $category->slug;
    					$catClasses[] = "fc-event-cat-" . $category->term_id;
    				}
    				
    			if (count($aTags))
    				foreach($aTags as $tag) {
    					$catClasses[] = "fc-event-tag-" . $tag->slug;
    					$catClasses[] = "fc-event-tag-" . $tag->term_id;
    				}
    // mod end
    				
    ....

    Then in the events array assembly I added this line:

    
    $calendar[] = array(
    				'title' => $event->post_title,
    				'start' => $start,
    				'end' => $end,
    				'className' => implode(" ", $catClasses), // <<<< added line
    				'allDay' => em_is_all_day($id), 
    				'url' => get_permalink($id)
    			);
    

    This is arg described in FullCalendar documentation.
    This gives me some additional classes in the list of rendered events, like that:

    ...<a href="http://some.url/" class="
    fc-event fc-event-hori fc-event-start fc-event-end
    fc-event-cat-zajecia-oferta-stala
    fc-event-cat-118
    fc-event-tag-dzieci
    fc-event-tag-182
    fc-event-tag-gimnastyka
    fc-event-tag-180 ... " style="...."> ....

    Now, I’m able to add i.e. different colors for events under different categories, assign icons etc.
    Ofc it will work as soon as you have an event assigned to any event-rlated taxonomy (categories or tags).

    #4801
    Bartosz
    Keymaster

    Thank you so much Kuba!
    That’s a very good idea.

    We’ll push that with an upcoming release.

    #4958
    Kuba S
    Participant

    Bartosz, thanks for introducing this in official release so quickly ;)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.