/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; } $location_post_types = array_keys(ATTENT_LOCATION_POST_TYPES); $context = Timber::get_context(); if (is_post_type_archive($location_post_types)) { global $wp_query; $post_type = get_post_type_object($wp_query->query['post_type']); $page = get_page_by_path($post_type->rewrite['slug']); $context['page'] = new TimberPost($page->ID); $context['posts'] = new Timber\PostQuery(); $template = ['location-archive.twig']; } else if (is_singular($location_post_types)) { $context['post'] = new Timber\Post(); $template = ['location-single.twig']; } else if (is_post_type_archive('news')) { global $wp_query; $post_type = get_post_type_object($wp_query->query['post_type']); $page = get_page_by_path($post_type->rewrite['slug']); $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $posts = new Timber\PostQuery(); $pagination = $posts->pagination(); $total = $posts->found_posts; if ($paged > 1) { $previous = new Timber\PostQuery(['post_type' => 'news', 'posts_per_page' => ($paged - 1) * 5]); $posts = [...$previous, ...$posts]; } $context['loader'] = $total - count($posts) > 10 ? 10 : $total - count($posts); $context['pagination'] = $pagination; $context['posts'] = array_chunk([...$posts], 5); $context['page'] = new TimberPost($page->ID); $template = ['news-archive.twig']; } else if (is_singular('news')) { $context['post'] = new Timber\Post(); $template = ['news-single.twig']; } else if (is_page()) { global $post; $ancestors = get_ancestors($post->ID, 'page'); $context['ancestors'] = $ancestors ? new Timber\PostQuery(['post_type' => 'page', 'post__in' => $ancestors, 'orderby' => 'post__in']) : []; $context['post'] = new TimberPost(); $template = [$context['post']->_wp_page_template . '.twig', 'page.twig']; } else if (is_search()) { $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $posts = new Timber\PostQuery(); $pagination = $posts->pagination(); $total = $posts->found_posts; if ($paged > 1) { $previous = new Timber\PostQuery(['posts_per_page' => ($paged - 1) * 10, 's' => get_search_query()]); $posts = [...$previous, ...$posts]; } $context['loader'] = $total - count($posts) > 10 ? 10 : $total - count($posts); $context['pagination'] = $pagination; $context['posts'] = array_chunk([...$posts], 10); $template = ['search.twig']; } else if (is_404()) { $template = ['errors/404.twig']; } Timber::render($template, $context); ?>