Okay
  Public Ticket #2319074
Event Colors with Multiple Categories
Closed

Comments

  • obsidianwebsolutions started the conversation

    I have the calendar setting set to show events by their associated category color. When I have multiple categories assigned to one event, is there anyway to choose which color takes priority without manually entering the color code?

  •  894
    Zhivko replied

    Hi,

    No, currently the calendar picks the color from the first event category found.

    You can add custom hook that can prioritize the category color.

    Add following code in your theme function.php file:

    add_action('stec_after_html', function() {
        ?>
        <script type="text/javascript">
            (function ($) {
                
               /**
                * SETUP
                * ENTER PRIORITY CATEGORIES IDS [HIGHEST -> LOWEST]
                */
                var priorityCategories = [302, 312];              
                function getPriorityColor(categories) {
                    
                    var color = false;
                    
                    $.each(priorityCategories, function () {
                        
                        var pId = parseInt(this, 10);
                        
                        $.each(categories, function () {
                            if (this.id === pId) {
                                color = this.color;
                                return false; // break;
                            }
                        });
                        
                        if (color){
                            return false; // break;
                        }
                    });                 return color;
                }             $.stecExtend(function (m) {
                    $.each(m.calData.eventsPool, function () {                     var color;                     if (this.category.length <= 0) {
                            return true; // continue;
                        }                     color = getPriorityColor(this.category);                     if (color) {
                            this.color = color;
                        }                 });
                }, 'onAddToEventsPool');
            })(window.jQuery);
        </script>
        <?php
    });

    You will have to change the categories id for priorityCategories (Check the SETUP comment)


    Stachethemes Developer

  • obsidianwebsolutions replied

    Thanks. That should work for now.