Skip to content

Instantly share code, notes, and snippets.

@chikaibeneme
Created August 22, 2025 04:28
Show Gist options
  • Select an option

  • Save chikaibeneme/275a307a0c8313e14b709da1adeae866 to your computer and use it in GitHub Desktop.

Select an option

Save chikaibeneme/275a307a0c8313e14b709da1adeae866 to your computer and use it in GitHub Desktop.
display organizers in list view for TEC
/**
* Auto-create template override for event organizers in list view
*/
// Hook into init to create the template override
add_action( 'init', 'create_event_organizers_template_override' );
function create_event_organizers_template_override() {
// Only run once
if ( get_option( 'event_organizers_template_created' ) ) {
return;
}
$theme_dir = get_stylesheet_directory();
$template_dir = $theme_dir . '/tribe/events/v2/list';
$template_file = $template_dir . '/event.php';
// Create directories if they don't exist
if ( ! file_exists( $template_dir ) ) {
wp_mkdir_p( $template_dir );
}
// Create the template file
if ( ! file_exists( $template_file ) ) {
$template_content = '<?php
/**
* View: List Event with Organizers
*
* Auto-generated template override for event organizers
*/
$container_classes = [ \'tribe-common-g-row\', \'tribe-events-calendar-list__event-row\' ];
$container_classes[\'tribe-events-calendar-list__event-row--featured\'] = $event->featured;
$event_classes = tribe_get_post_class( [ \'tribe-events-calendar-list__event\', \'tribe-common-g-row\', \'tribe-common-g-row--gutters\' ], $event->ID );
?>
<div <?php tribe_classes( $container_classes ); ?>>
<?php $this->template( \'list/event/date-tag\', [ \'event\' => $event ] ); ?>
<div class="tribe-events-calendar-list__event-wrapper tribe-common-g-col">
<article <?php tribe_classes( $event_classes ) ?>>
<?php $this->template( \'list/event/featured-image\', [ \'event\' => $event ] ); ?>
<div class="tribe-events-calendar-list__event-details tribe-common-g-col">
<header class="tribe-events-calendar-list__event-header">
<?php $this->template( \'list/event/date\', [ \'event\' => $event ] ); ?>
<?php $this->template( \'list/event/title\', [ \'event\' => $event ] ); ?>
<?php $this->template( \'list/event/venue\', [ \'event\' => $event ] ); ?>
</header>
<?php $this->template( \'list/event/description\', [ \'event\' => $event ] ); ?>
<?php $this->template( \'list/event/cost\', [ \'event\' => $event ] ); ?>
<?php
// Add event organizers here
$organizer_ids = tribe_get_organizer_ids( $event->ID );
if ( ! empty( $organizer_ids ) ) {
$organizer_links = [];
foreach ( $organizer_ids as $organizer_id ) {
if ( $organizer_id > 0 ) {
$organizer_name = get_the_title( $organizer_id );
$organizer_url = get_permalink( $organizer_id );
if ( $organizer_name && $organizer_url ) {
$organizer_links[] = \'<a href="\' . esc_url( $organizer_url ) . \'" class="tribe-event-organizer-link">\' . esc_html( $organizer_name ) . \'</a>\';
}
}
}
if ( ! empty( $organizer_links ) ) {
echo \'<div class="tribe-events-calendar-list__event-organizers">\';
echo \'<span class="tribe-event-organizers-label">\' . esc_html__( \'Organized by:\', \'the-events-calendar\' ) . \'</span> \';
echo \'<span class="tribe-event-organizers">\' . implode( \', \', $organizer_links ) . \'</span>\';
echo \'</div>\';
}
}
?>
</div>
</article>
</div>
</div>';
file_put_contents( $template_file, $template_content );
// Mark as created
update_option( 'event_organizers_template_created', true );
}
}
// Add CSS styling
add_action( 'wp_head', 'add_event_organizers_list_view_styles' );
function add_event_organizers_list_view_styles() {
if ( tribe_is_event_query() && tribe_is_list_view() ) {
?>
<style>
.tribe-events-calendar-list__event-organizers {
margin-top: 8px;
margin-bottom: 8px;
font-size: 0.85em;
color: #666;
line-height: 1.4;
}
.tribe-event-organizers-label {
font-weight: 600;
margin-right: 5px;
color: #333;
}
.tribe-event-organizer-link {
color: #0073aa;
text-decoration: none;
transition: color 0.2s ease;
background: #f7f7f7;
padding: 2px 6px;
border-radius: 3px;
margin-right: 3px;
display: inline-block;
margin-bottom: 3px;
}
.tribe-event-organizer-link:hover {
color: #005a87;
background: #e7f3ff;
text-decoration: none;
}
.tribe-event-organizers {
font-style: italic;
}
</style>
<?php
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment