/wp-admin/plugins.php'; return; } if (!class_exists('acf') ) { echo 'ACF not activated. Make sure you activate the plugin in /wp-admin/plugins.php'; return; } $context = Timber::get_context(); if (is_front_page()) { $meta_query = [['key' => 'performance_datetime', 'value' => date('Y-m-d H:i:s'), 'compare' => '>=', 'type' => 'DATETIME']]; $display = get_field('display', 'option'); if ($display === 'events') { $posts = Timber::get_posts(['numberposts' => -1, 'post_type' => ['event', 'festival'], 'meta_query' => $meta_query, 'post__in' => get_field('events', 'option') ?: [0], 'orderby' => ['meta_value' => 'asc']]); $posts = empty($posts) ? Timber::get_posts(['numberposts' => 1, 'post_type' => ['event', 'festival'], 'meta_key' => 'performance_datetime', 'meta_query' => $meta_query, 'orderby' => ['meta_value' => 'asc']]) : $posts; } if ($display === 'custom') { $item = (object) get_field('custom', 'option'); $item->thumbnail = new TimberImage($item->thumbnail); $posts = [$item]; } $meta_query[] = ['key' => 'ticket_status', 'value' => ['C', 'S'], 'compare' => 'NOT IN']; $items = Timber::get_posts(['numberposts' => 4, 'post_type' => ['event', 'festival'], 'meta_key' => 'performance_datetime', 'meta_query' => $meta_query, 'orderby' => ['meta_value' => 'asc']]); $context['posts'] = $posts; $context['featured'] = get_field('featured', 'option'); $context['arrangements'] = get_field('arrangements', 'option'); $context['items'] = order_events_by_month($items); $template = ['home.twig']; } else if (is_page()) { $context['post'] = new Timber\Post(); $template = ['page-' . $context['post']->_wp_page_template . '.twig', 'page-' . $context['post']->post_name . '.twig', 'page.twig']; } else if (is_tax(['artist', 'collection'])) { $posts = new Timber\PostQuery(); $context['term'] = new Timber\Term(); $context['months'] = order_events_by_month($posts); $context['posts'] = $posts; $template = ['event-taxonomy.twig']; } else if (is_post_type_archive(['event', 'festival'])) { global $posts; $genres = Timber::get_terms('genre', ['parent' => 0, 'hide_empty' => true]); $subgenres = Timber::get_terms('genre', ['exclude' => wp_list_pluck($genres, 'id'), 'hide_empty' => true]); $context['filters'] = Timber::get_terms('filter', ['hide_empty' => true]); $context['months'] = order_events_by_month($posts); $context['subgenres'] = $subgenres; $context['genres'] = $genres; $template = ['event-archive.twig']; } else if (is_singular('event')) { $post = new Timber\Post(); $more = get_more_from_artist($post); $tips = get_event_tips($post); if (!is_event_in_future($post) && !empty($more)) { $term = wp_get_post_terms($post->ID, 'artist')[0]; $url = count($more) > 1 ? get_term_link($term) : get_permalink($more[0]); wp_safe_redirect($url, 301); exit(); } $context['future'] = is_event_in_future($post); $context['arrangements'] = $context['future'] ? get_arrangements($post) : false; $context['pricing'] = $context['future'] ? flatten_event_pricing($post) : false; $context['more'] = order_events_by_month($more); $context['post'] = $post; $context['tips'] = $tips; $template = ['event-single.twig']; } else if (is_singular('festival')) { $festival = new TimberPost(); $context['events'] = Timber::get_posts(['numberposts' => -1, 'post_type' => 'festival_event', 'meta_query' => [['key' => 'festival', 'value' => $festival->id]], 'orderby' => ['menu_order' => 'asc']]); $context['pages'] = Timber::get_posts(['numberposts' => -1, 'post_type' => 'festival_page', 'meta_query' => [['key' => 'festival', 'value' => $festival->id], ['key' => 'show_in_menu', 'value' => 1]], 'orderby' => ['menu_order' => 'asc']]); $context['news'] = Timber::get_posts(['numberposts' => -1, 'post_type' => 'festival_news', 'meta_query' => [['key' => 'festival', 'value' => $festival->id]]]); $context['future'] = is_event_in_future($festival); $context['pricing'] = $context['future'] ? flatten_event_pricing($festival) : false; $context['festival'] = $festival; $template = [ 'festivals/' . $festival->theme . '/home.twig', 'festival-home.twig' ]; } else if (is_post_type_archive(['festival_event', 'festival_news'])) { global $wp_query; $posts = new Timber\PostQuery(); $context['events'] = Timber::get_posts(['numberposts' => -1, 'post_type' => 'festival_event', 'meta_query' => [['key' => 'festival', 'value' => $wp_query->festival->id]], 'orderby' => ['menu_order' => 'asc']]); $context['pages'] = Timber::get_posts(['numberposts' => -1, 'post_type' => 'festival_page', 'meta_query' => [['key' => 'festival', 'value' => $wp_query->festival->id], ['key' => 'show_in_menu', 'value' => 1]], 'orderby' => ['menu_order' => 'asc']]); $context['news'] = Timber::get_posts(['numberposts' => -1, 'post_type' => 'festival_news', 'meta_query' => [['key' => 'festival', 'value' => $wp_query->festival->id]]]); $context['future'] = is_event_in_future($wp_query->festival); $context['pricing'] = $context['future'] ? flatten_event_pricing($wp_query->festival) : false; $context['festival'] = $wp_query->festival; $context['posts'] = $posts; $template = [ 'festivals/' . $wp_query->festival->theme . '/' . str_replace('festival_', null, $wp_query->query['post_type']) . '-archive.twig', str_replace('_', '-', $wp_query->query['post_type']) . '-archive.twig' ]; } else if (is_singular(['festival_event', 'festival_news'])) { global $wp_query; $post = new Timber\Post(); $context['events'] = Timber::get_posts(['numberposts' => -1, 'post_type' => 'festival_event', 'meta_query' => [['key' => 'festival', 'value' => $wp_query->festival->id]], 'orderby' => ['menu_order' => 'asc']]); $context['pages'] = Timber::get_posts(['numberposts' => -1, 'post_type' => 'festival_page', 'meta_query' => [['key' => 'festival', 'value' => $wp_query->festival->id], ['key' => 'show_in_menu', 'value' => 1]], 'orderby' => ['menu_order' => 'asc']]); $context['news'] = Timber::get_posts(['numberposts' => -1, 'post_type' => 'festival_news', 'meta_query' => [['key' => 'festival', 'value' => $wp_query->festival->id]]]); $context['future'] = is_event_in_future($wp_query->festival); $context['pricing'] = $context['future'] ? flatten_event_pricing($wp_query->festival) : false; $context['festival'] = $wp_query->festival; $context['post'] = $post; $template = [ 'festivals/' . $wp_query->festival->theme . '/' . str_replace('festival_', null, $wp_query->query['post_type']) . '-single.twig', str_replace('_', '-', $wp_query->query['post_type']) . '-single.twig' ]; } else if (is_singular('festival_page')) { global $wp_query; $post = new Timber\Post(); $context['events'] = Timber::get_posts(['numberposts' => -1, 'post_type' => 'festival_event', 'meta_query' => [['key' => 'festival', 'value' => $wp_query->festival->id]]]); $context['pages'] = Timber::get_posts(['numberposts' => -1, 'post_type' => 'festival_page', 'meta_query' => [['key' => 'festival', 'value' => $wp_query->festival->id], ['key' => 'show_in_menu', 'value' => 1]], 'orderby' => ['menu_order' => 'asc']]); $context['news'] = Timber::get_posts(['numberposts' => -1, 'post_type' => 'festival_news', 'meta_query' => [['key' => 'festival', 'value' => $wp_query->festival->id]]]); $context['future'] = is_event_in_future($wp_query->festival); $context['pricing'] = $context['future'] ? flatten_event_pricing($wp_query->festival) : false; $context['festival'] = $wp_query->festival; $context['post'] = $post; $template = [ 'festivals/' . $wp_query->festival->theme . '/page-' . $post->post_name . '.twig', 'festivals/' . $wp_query->festival->theme . '/page.twig', 'festival-page.twig' ]; } else if (is_post_type_archive('arrangement')) { $post_type = get_queried_object(); $page = get_page_by_path($post_type->rewrite['slug']); $context['page'] = new TimberPost($page->ID); $context['posts'] = new Timber\PostQuery(); $template = ['arrangement-archive.twig']; } else if (is_singular('arrangement')) { $post = new TimberPost(); $context['performances'] = order_arrangements_by_month($post); $context['post'] = $post; $template = ['arrangement-single.twig']; } else if (is_post_type_archive('news')) { $context['posts'] = new Timber\PostQuery(); $template = ['news-archive.twig']; } else if (is_singular('news')) { $post = new TimberPost(); $context['news'] = Timber::get_posts(['numberposts' => 3, 'post_type' => 'news', 'post__not_in' => [$post->ID]]); $context['post'] = $post; $template = ['news-single.twig']; } else if (is_singular('narrowcasting')) { $post = new TimberPost(); $context['scheduled'] = has_scheduled_screens($post); $context['facilities'] = parse_facilities($post); $context['venue'] = parse_venue($post); $context['post'] = $post; $template = ['narrowcasting-' . $post->post_name . '.twig', 'narrowcasting.twig']; } else if (is_search()) { $allowed = ['page', 'event', 'news']; $filters = isset($_GET['types']) ? $_GET['types'] : 'page,event,news'; $filters = explode(',', $filters); $filters = array_intersect($filters, $allowed); if (count($filters) !== count($allowed)) { $links = [ 'event' => in_array('event', $filters) ? array_diff($filters, ['event']) : array_merge($filters, ['event']), 'page' => in_array('page', $filters) ? array_diff($filters, ['page']) : array_merge($filters, ['page']), 'news' => in_array('news', $filters) ? array_diff($filters, ['news']) : array_merge($filters, ['news']) ]; } else { $links = [ 'event' => ['event'], 'page' => ['page'], 'news' => ['news'] ]; } $context['posts'] = new Timber\PostQuery(); $context['filters'] = $filters; $context['links'] = $links; $template = ['search.twig']; } else if (is_404()) { $meta_query = [['key' => 'performance_datetime', 'value' => date('Y-m-d H:i:s'), 'compare' => '>=', 'type' => 'DATETIME']]; $context['posts'] = Timber::get_posts(['numberposts' => 3, 'post_type' => ['event', 'festival'], 'meta_key' => 'performance_datetime', 'meta_query' => $meta_query, 'orderby' => ['meta_value' => 'asc']]); $template = ['errors/404.twig']; } Timber::render($template, $context); ?>