Okay
  Public Ticket #3019695
Icon colour to reflect organizer?
Closed

Comments

  •  2
    publicspace started the conversation

    Part of what I really like about the design of this events calendar is the use of the coloured icon with the date, superimposed over the image. The coloured icons become a quick way of connecting and contrasting the events displayed. 

    In our case it seems natural to use the icon colour to indicate the organizer, rather than the category.  But it is tedious to do it manually for every event. 

    So I want to ask if there is a possible php code to make the icon colour automatically correspond to the organizer ID?  In other words, something that achieves: 

    if organizer = id#93   then icon color = #7e816e
    if organizer = id#99   then icon color = #a2c89e
    etc.

    I realise that is not in the spec, and it may be impossible, but I want to ask.

    Thank you and best wishes. 

  •  877
    Zhivko replied

    Yes, it's possible via filter hook.

    The code:

    add_filter('stec_event_get_front_data', function ($data) {
        if (!isset($data['organizers']) || false === is_array($data['organizers']) || !$data['organizers']) {
            return $data;
        }     $organizer_id = $data['organizers'][0]->id;     switch ($organizer_id) {         case 101:
                $data['color'] = '#FF0000';
                break;
           case 102:
                $data['color'] = '#0000FF';
                break;             // etc...     }     return $data;
    });

    where 101, 102 etc... are the organizers id numbers

    $data['color'] is the event color.



    Stachethemes Developer

  •  2
    publicspace replied

    Awesome!  I've just tried it and it works.  

    It enables organisers to post events simply with their own distinctive colour from their logo or branding.  The icon colour even changes correctly when I edit an existing event in the frontend and change the organiser.

    Maybe you advertise this feature already and I missed it, but it is definitely a selling feature! 

    Thank you.

  •   publicspace replied privately
  •  877
    Zhivko replied

    The code for the single page:

    add_action('stec_single_after_content', function () {
        ?>
        <script type='text/javascript'>
            (function($) {
                $(function() {                 if (stecSingleEvent.organizers.length > 0) {
                        const organizerId = stecSingleEvent.organizers[0].id;
                        let color = stecSingleEvent.color;                     // colors config here                     switch (organizerId) {                         case 101:
                                color = '#FF0000';
                                break;                         case 102:
                                color = '#0000FF';
                                break;
                        }                     $('.stec-layout-single-preview-left-icon').css('background-color', color);                 }
                });
            })(window.jQuery);
        </script>
    <?php
    });



    Stachethemes Developer

  •   publicspace replied privately
  •  877
    Zhivko replied

    Place the code in your theme functions.php file. 

    Let me know when you've done this to take a look at the single page.


    Stachethemes Developer