<?php /** * The main template file * This is the most generic template file in a WordPress theme * and one of the two required files for a theme (the other being style.css). * It is used to display a page when nothing more specific matches a query. * E.g., it puts together the home page when no home.php file exists * * Methods for TimberHelper can be found in the /lib sub-directory * * @package WordPress * @subpackage Timber * @since Timber 0.1 */ use Lumberjack\PostTypes\Post; $context = Timber::get_context(); $context['posts'] = Post::all(); Timber::render(['posts.twig'], $context);
<?php /** * Search results page * * Methods for TimberHelper can be found in the /lib sub-directory * * @package WordPress * @subpackage Timber * @since Timber 0.1 */ use Lumberjack\PostTypes\Post; $templates = ['search.twig', 'posts.twig', 'generic-page.twig']; $context = Timber::get_context(); $searchQuery = get_search_query(); $context['title'] = 'Search results for ' . $searchQuery; $context['posts'] = Post::query(['s' => $searchQuery]); Timber::render($templates, $context);
<?php /** * The template for displaying Author Archive pages * * Methods for TimberHelper can be found in the /lib sub-directory * * @package WordPress * @subpackage Timber * @since Timber 0.1 */ global $wp_query; use Lumberjack\PostTypes\Post; $data = Timber::get_context(); if (isset($wp_query->query_vars['author'])) { $author = new TimberUser($wp_query->query_vars['author']); $data['author'] = $author; $data['title'] = 'Author Archives: ' . $author->name(); $data['posts'] = Post::query(['author' => $author->ID]); } Timber::render(['author.twig', 'posts.twig', 'generic-page.twig'], $data);
* * Learn more: http://codex.wordpress.org/Template_Hierarchy * * Methods for TimberHelper can be found in the /lib sub-directory * * @package WordPress * @subpackage Timber * @since Timber 0.2 */ use Lumberjack\PostTypes\Post; $templates = ['posts.twig', 'generic-page.twig']; $data = Timber::get_context(); $data['title'] = 'Archive'; if (is_day()) { $data['title'] = 'Archive: ' . get_the_date('D M Y'); } elseif (is_month()) { $data['title'] = 'Archive: ' . get_the_date('M Y'); } elseif (is_year()) { $data['title'] = 'Archive: ' . get_the_date('Y'); } elseif (is_tag()) { $data['title'] = single_tag_title('', false); } elseif (is_category()) { $data['title'] = single_cat_title('', false); array_unshift($templates, 'archive-' . get_query_var('cat') . '.twig'); } elseif (is_post_type_archive()) { $data['title'] = post_type_archive_title('', false); array_unshift($templates, 'archive-' . get_post_type() . '.twig'); } // TODO: Currently only works for posts, fix for custom post types $data['posts'] = Post::query(); Timber::render($templates, $data);