Okay
  Public Ticket #2700196
Organizer Pages
Closed

Comments

  • Steve Hancock started the conversation

    Hi,
    I am currently building a site that has events and content provided by contributors. Because of this, I want to be able to create a custom organizer page for each organizer that showcases their events and posts. Is there a way to either customize the existing Organizer page template, or for the link to the organizer from events on the calendar to be changed so that it points to a custom page rather than the default organizer page?
    Thanks

  •  770
    Zhivko replied

    Hi,

    You can override the default template by adding following filter in your theme or child-theme functions.php file:

    add_filter('page_template', function($template) {
        $post = get_post();
                  
        // Admin_Helper resides in \ Stachethemes \ Stec \ namespace   
        if ($post->ID === \ Stachethemes \ Stec \ Admin_Helper::get_stec_page('organizer')) {
            
            $template = get_stylesheet_directory() . '/' . 'custom-organizers.php';
        }
        return $template;
    }, 9999);
    

    Stachethemes Developer

  • Steve Hancock replied

    Thanks for your reply. Unfortunately, this doesn't really give me the results I need. I am using Elementor to build the site and could do with using this to create the organizer pages. Is there a way to do this, or is there alternatively a way to point the organizer page links to other pages on the site, set up for each individual organizer?

  •  770
    Zhivko replied

    Sorry, the only way to override the organizer's permalink at the moment is by editing the method get_permalink() in file \stachethemes_event_calendar\assets\php\o.organizer.php line 53.

    If you don't have too many organizers you could add switch there and point each organizer to their link.

    Example:

    public function get_permalink() {
            switch ($this->id) {
                case 1: // case for organizer with id#1
                    return esc_url('https://...');
                case 2: // case for organizer with id#2                 return esc_url('https://...');
                case 3: // case for organizer with id#3
                    return esc_url('https://...');
                    
                default:                 // The default behaviour if no case is found                 if (null !== $this->permalink) {
                        return esc_url($this->permalink);
                    }                 $page_id = Admin_Helper::get_stec_page('organizer');                 if (!$page_id) {
                        return null;
                    }                 $page = Admin_Helper::get_permalinks('organizer', 'stec_organizer');                 if (class_exists('SitePress')) {
                        $default_locale = Admin_Helper::get_default_locale();
                        if ($default_locale !== ICL_LANGUAGE_CODE) {
                            $page = ICL_LANGUAGE_CODE . '-' . $page;
                        }
                    }                 $replace = apply_filters('stec_organizer_get_permalink_replace_name_spaces_with', '_');                 $name = str_replace(' ', $replace, $this->get_name());                 return esc_url(home_url($page . '/' . $name));
            }
        }


    Stachethemes Developer

  • Steve Hancock replied

    Thanks for the response. 

    I have now managed to tweak the o.organizer.php to change line 78 from this:

    return esc_url(home_url($page . '/' . $name));

    to:

    return esc_url(home_url('coaches/' . $name));
    

    Which gives me the results I want, as all organizers on the site are set up as posts with the category 'coaches', with permalinks set up as follows: domain.com/coaches/coach_name.

    While this is a good proof of concept, this code will obviously be overwritten when the plugin updates, so is not a permanent solution. Is there a chance of something like this being implemented in future versions? All I really need is a way to input an organizer permalink without an actual page being created, so that I can create a custom page in the correct location.
    Does that make sense?

  •  770
    Zhivko replied

    Sorry for the late reply.

    Indeed, modifying the core can't be permanent solution.

    Therefore I'll place filter in the next update for the organizer permalinks.

    Meanwhile you can do following:

    Open file stachethemes_event_calendar\assets\php\o.organizer.php 

    and on line 53 replace the whole function get_permalink() { ... }

    with this one:

        public function get_permalink() {
            if (null !== $this->permalink) {
                return esc_url($this->permalink);
            }         $page_id = Admin_Helper::get_stec_page('organizer');         if (!$page_id) {
                return null;
            }         $page = Admin_Helper::get_permalinks('organizer', 'stec_organizer');         if (class_exists('SitePress')) {
                $default_locale = Admin_Helper::get_default_locale();
                if ($default_locale !== ICL_LANGUAGE_CODE) {
                    $page = ICL_LANGUAGE_CODE . '-' . $page;
                }
            }         $replace = apply_filters('stec_organizer_get_permalink_replace_name_spaces_with', '_');         $name = str_replace(' ', $replace, $this->get_name());         return apply_filters('stec_organizer_get_permalink', esc_url(home_url($page . '/' . $name)), $this);
        }

    Then open your theme or child-theme functions.php file and implement a filter similar to the one I've sent you previously:

    add_filter('stec_organizer_get_permalink', function($link, $organizer) {
        switch ($organizer->get_id()) {
            case 1: // case for organizer with id#1
                return esc_url('https://...');
            case 2: // case for organizer with id#2
                return esc_url('https://...');         case 3: // case for organizer with id#3
                return esc_url('https://...');         default:
                return $link;
        }
    }, 10, 2);

    This way the changes will be preserved on calendar update.


    Stachethemes Developer