'category', 'hide_empty' => true, ]); /* * Recent Posts - added globally so available in all templates */ $context['recent_posts'] = Timber::get_posts([ 'post_type' => 'post', 'posts_per_page' => 5, 'orderby' => 'date', 'order' => 'DESC', ]); /* * Setting up Timber */ if ( is_singular() ) : $context['post'] = new TimberPost(); else : $context['pagination'] = Timber::get_pagination(); $context['posts'] = new Timber\PostQuery(); endif; /* * Single Post Type Templates */ if ( is_single() ) : $template = '04-templates/single-blog/single-blog.twig'; if ( is_singular( 'case-study' ) ) : $template = '04-templates/base/base-page-template-blocks/base-page-template-blocks.twig'; elseif ( is_singular( 'block-showcase' ) ) : $template = '04-templates/single-block-showcase/single-block-showcase.twig'; elseif ( is_singular( 'event' ) ) : $template = '04-templates/single-page/single-page.twig'; elseif ( is_singular( 'news' ) || is_singular( 'whitepaper' ) ) : $template = '04-templates/single-blog/single-blog.twig'; elseif ( is_singular( 'providers' ) ) : $template = '04-templates/single-providers/single-providers.twig'; elseif ( is_singular( 'condition' ) ) : $template = '04-templates/single-condition/single-condition.twig'; endif; /* * Basic Page Template */ elseif ( is_page() ) : $template = '04-templates/single-page/single-page.twig'; elseif ( is_home() ) : global $paged; if (!isset($paged) || !$paged) { $paged = 1; } $context['post'] = new TimberPost(); $args = [ 'post_type' => 'post', 'posts_per_page' => get_option('posts_per_page'), 'paged' => $paged ]; $context['posts'] = new Timber\PostQuery($args); // or Timber::get_posts() $context['pagination'] = Timber::get_pagination(); $template = '04-templates/articles-overview/articles-overview.twig'; /* * Search Results Template */ elseif ( is_search() ) : global $query_string; if ( ! empty( get_search_query() ) ) : wp_parse_str( $query_string, $search_query ); $context['items'] = new Timber\PostQuery( $search_query ); $context['search_query'] = get_search_query(); if ( $context['search_query'] !== '' ) { $context['results_count'] = $context['posts']->found_posts; } else { $context['results_count'] = 0; } endif; $context['pagination'] = Timber::get_pagination(); $template = '04-templates/default/default-search-results/default-search-results.twig'; /* * Archive Templates */ elseif ( is_archive() ) : $context['post'] = new TimberPost(); $context['pagination'] = Timber::get_pagination(); $context['term'] = Timber::get_term(get_queried_object()); if ( is_category() ) : // Get the Blog page ID $blog_page_id = get_option('page_for_posts'); if ($blog_page_id) { $context['blog_page'] = new TimberPost($blog_page_id); $context['blog_title'] = $context['blog_page']->title; } else { $context['blog_title'] = 'Blog'; } $context['taxonomy'] = 'category'; $context['post']->title = get_the_archive_title(); $template = '04-templates/articles-overview/articles-overview.twig'; elseif ( is_post_type_archive( 'blog' ) ) : $context['post']->title = get_the_archive_title(); $template = '04-templates/articles-overview/articles-overview.twig'; elseif ( is_post_type_archive( 'case-study' ) ) : $context['taxonomy'] = 'case-studies-categories'; $context['post']->title = get_the_archive_title(); $template = '04-templates/articles-overview/articles-overview.twig'; elseif ( is_tax( 'case-study-categories' ) ) : $context['taxonomy'] = 'case-studies-categories'; $context['post']->title = get_the_archive_title(); $template = '04-templates/articles-overview/articles-overview.twig'; elseif ( is_post_type_archive( 'whitepaper' ) ) : $context['taxonomy'] = 'whitepaper-categories'; $context['post']->title = get_the_archive_title(); $template = '04-templates/articles-overview/articles-overview.twig'; elseif ( is_tax( 'whitepaper-categories' ) ) : $context['taxonomy'] = 'whitepaper-categories'; $context['post']->title = get_the_archive_title(); $template = '04-templates/articles-overview/articles-overview.twig'; elseif ( is_post_type_archive( 'event' ) ) : $context['taxonomy'] = 'event-categories'; $context['post']->title = get_the_archive_title(); $template = '04-templates/articles-overview/articles-overview.twig'; elseif ( is_tax( 'event-categories' ) ) : $context['taxonomy'] = 'event-categories'; $context['post']->title = get_the_archive_title(); $template = '04-templates/articles-overview/articles-overview.twig'; elseif ( is_tag() ) : $context['post']->title = get_the_archive_title(); $template = '04-templates/articles-overview/articles-overview.twig'; elseif ( is_author() ) : $context['post']['title'] = 'Posts by: ' . get_the_author(); elseif ( is_date() ) : $context['post']['title'] = get_the_archive_title(); endif; endif; // echo $template; die; foreach ( $context['posts'] as $post ) { $raw = get_post_field('post_content', $post->ID); if (strpos($raw, '') !== false) { $parts = explode('', $raw); $post->content_before_more = apply_filters('the_content', $parts[0]); } } Timber::render( [ $template, 'base-page.twig' ], $context );