• Each of my events has two kinds of categories: one for a type of dance and one for a level of difficulty, e.g. ‘Intermediate Ballet Technique’ has the two categories ‘ballet’ and ‘intermediate’.

    I have two calendars, one to display events by dance and one to display events by level.
    I also have a colour associated with each category.

    category colours representing level are showing up in my dance calendar. I would like to only see the category colours for dance show on the dance calendar.

    Perhaps I could write some code to get the category filter for the calendar and compare that list against the categories for each event. A match would then allow me to get the colour associated with matched category, thereby allowing me to display the correct category colour in the relevant calendar.

    Please advise.

    Thanks,
    Tom

    https://wordpress.org/plugins/event-organiser/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter tjsherlock

    (@tjsherlock)

    Can I modify the function, page_styles( ), in event-organiser-calender.php to return a list of event-category terms limited to the filter applied in the shortcode, eo_fullcalendar? One argument is ‘category’ or ‘event_category’ with a list of permitted categories.

    /**
    	 * Prints page styles
    	 */
    	function page_styles(){
    		$css = '';
    		if ( $terms = get_terms( 'event-category', array( 'hide_empty' => 0 ) ) ):
    			foreach ( $terms as $term ):
    				$slug = sanitize_html_class( $term->slug );
    				$color = esc_attr( eo_get_category_color( $term ) ); //tjs 2015 Nov 5
    				$css .= ".cat-slug-{$slug} span.ui-selectmenu-item-icon{ background: {$color}; }\n";
    			endforeach;
    		endif;
    
    		wp_enqueue_style( 'eo_calendar-style' );
    		wp_enqueue_style( 'eventorganiser-style' );
    		//See trac ticket: https://core.trac.wordpress.org/ticket/24813
    		if( ( !defined( 'SCRIPT_DEBUG' ) || !SCRIPT_DEBUG ) && version_compare( get_bloginfo( 'version' ), '3.7', '<' ) ){
    			$css = "<style type='text/css'>\n" . $css . "</style>";
    		}
    
    		wp_add_inline_style( 'eo_calendar-style', $css );
    	}
    Thread Starter tjsherlock

    (@tjsherlock)

    the function eventorganiser_public_fullcalendar found in event-organiser-ajax.php pulls in event categories associated with an event. It disregards the event category filter applied to the calendar. It then selects an event color instead of the relevant category color.

    I would like to rework this method to take into consideration the event category filter when displaying a category color associated with an event.

    Plugin Author Stephen Harris

    (@stephenharris)

    That function uses eo_get_event_color() to retrieve the event colour. This is done without any reference to its context (i.e. which calendar is being rendered).

    You could get round that by inspecting $_POST to determine if and which calendar you’re one (keep in mind that $_POST might be empty – as the event colour is used elsewhere).

    The only issue with that method, is that what $_POST contains is part of the internal workings of the plug-in and does not form part of its exposed API: in short, it may change, and without warning.

    Also keep in mind that the calendar is cached and changes won’t take effect until that is cleared (e.g. you update an event)

    Thread Starter tjsherlock

    (@tjsherlock)

    I made some changes to eventorganiser_public_fullcalendar in my local copy.

    I discovered that the category event filter was being stored under $request[‘tax_query’][0][‘terms’]. This allowed me to limit the available event category colors to the categories in the filter.

    Please see code snippet below. Please let me know if I am violating any rules of the plugin code or WP coding standards.

    //Include venue if this is set
    			$venue = eo_get_venue($post->ID);
    
    			if($venue && !is_wp_error($venue)){
    				$event['className'][]= 'venue-'.eo_get_venue_slug($post->ID);//deprecated. use eo-event-venue-{slug}
    				$event['venue']=$venue;
    			}
    
    //Added this
    //Event category filter
                $filters = $request['tax_query'][0][terms];
                $cat_color = '';
    
    			//Event categories
    			$terms = get_the_terms( $post->ID, 'event-category' );//compare against fc event category filter
    			$event['category']=array();
    			if($terms):
    				foreach ($terms as $term):
                        if($filters): //Added $filters loop tjs 2015 Nov 10
                          foreach($filters as $filter)://Added $filters loop tjs 2015 Nov 10
                            if($term->slug===$filter){ //Added $filters loop tjs 2015 Nov 10
                            $event['category'][]= $term->slug;
                            $event['className'][]='category-'.$term->slug;//deprecated. use eo-event-cat-{slug}
    
                            $cat_color = eo_get_category_color($term); //Added tjs 2015 Nov 10 Setting to last category color by default
                            }
                          endforeach;
                        endif;
    				endforeach;
    			endif;
    
    			//Event tags
    			if( eventorganiser_get_option('eventtag') ){
    				$terms = get_the_terms( $post->ID, 'event-tag' );
    				$event['tags'] = array();
    				if( $terms && !is_wp_error( $terms ) ):
    					foreach ($terms as $term):
    						$event['tags'][]= $term->slug;
    						$event['className'][]='tag-'.$term->slug;//deprecated. use eo-event-tag-{slug}
    					endforeach;
    				endif;
    			}
    
    			//Event colour
    			$event['textColor'] = '#ffffff'; //default text colour
    			/*if( eo_get_event_color() ) {
    				$event['color'] = eo_get_event_color();
    				$event['textColor'] = eo_get_event_textcolor( $event['color'] );
    			}*/
    
                if($cat_color) {//Added tjs 2015 Nov 12
                  	$event['color'] = $cat_color;
    				$event['textColor'] = eo_get_event_textcolor( $event['color']);
                }
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display category colour in calender per filter’ is closed to new replies.