Skip to content

Commit

Permalink
Merge branch '2.x' into reorder-twig-files
Browse files Browse the repository at this point in the history
  • Loading branch information
Levdbas committed May 21, 2024
2 parents 6d36147 + 0a6cb4d commit e938aae
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 114 deletions.
12 changes: 5 additions & 7 deletions 404.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<?php

/**
* The template for displaying 404 pages (Not Found)
*
* Methods for TimberHelper can be found in the /functions sub-directory
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.1
* The template for the 404 page
*/

namespace App;

use Timber\Timber;

$context = Timber::context();
Timber::render('templates/404.twig', $context);
31 changes: 15 additions & 16 deletions archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,35 @@
* Used to display archive-type pages if nothing more specific matches a query.
* For example, puts together date-based pages if no date.php file exists.
*
* Learn more: http://codex.wordpress.org/Template_Hierarchy
* Learn more: https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* Methods for TimberHelper can be found in the /lib sub-directory
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.2
*/

$templates = array('templates/archive.twig', 'templates/index.twig');
namespace App;

$context = Timber::context();
use Timber\Timber;

$templates = array('templates/archive.twig', 'templates/index.twig');

$context['title'] = 'Archive';
$title = 'Archive';
if (is_day()) {
$context['title'] = 'Archive: ' . get_the_date('D M Y');
$title = 'Archive: ' . get_the_date('D M Y');
} elseif (is_month()) {
$context['title'] = 'Archive: ' . get_the_date('M Y');
$title = 'Archive: ' . get_the_date('M Y');
} elseif (is_year()) {
$context['title'] = 'Archive: ' . get_the_date('Y');
$title = 'Archive: ' . get_the_date('Y');
} elseif (is_tag()) {
$context['title'] = single_tag_title('', false);
$title = single_tag_title('', false);
} elseif (is_category()) {
$context['title'] = single_cat_title('', false);
$title = single_cat_title('', false);
array_unshift($templates, 'templates/archive-' . get_query_var('cat') . '.twig');
} elseif (is_post_type_archive()) {
$context['title'] = post_type_archive_title('', false);
$title = post_type_archive_title('', false);
array_unshift($templates, 'templates/archive-' . get_post_type() . '.twig');
}

$context['posts'] = Timber::get_posts();
$context = Timber::context([
'title' => $title,
]);

Timber::render($templates, $context);
26 changes: 17 additions & 9 deletions author.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
<?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
*/

namespace App;

use Timber\Timber;

global $wp_query;

$context = Timber::context();
$context['posts'] = Timber::get_posts();
if ( isset( $wp_query->query_vars['author'] ) ) {
$author = Timber::get_user( $wp_query->query_vars['author'] );
$context['author'] = $author;
$context['title'] = 'Author Archives: ' . $author->name();
$author = false;
$title = false;

if (isset($wp_query->query_vars['author'])) {
$author = Timber::get_user($wp_query->query_vars['author']);
$title = 'Author Archives: ' . $author->name();
}

$context = Timber::context([
'title' => $title,
'author' => $author,
]);

Timber::render( array( 'templates/author.twig', 'templates/archive.twig' ), $context );
17 changes: 10 additions & 7 deletions functions.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<?php

/**
* Timber starter-theme
* https://github.com/timber/starter-theme
* Functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
* @link https://github.com/timber/starter-theme
*/

namespace App;

use Timber\Timber;

// Load Composer dependencies.
require_once __DIR__ . '/vendor/autoload.php';

require_once __DIR__ . '/src/StarterSite.php';

Timber\Timber::init();

// Sets the directories (inside your theme) to find .twig files.
Timber::$dirname = [ 'templates', 'views' ];
Timber::init();

new StarterSite();
27 changes: 15 additions & 12 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
<?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
* 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
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
*/

$context = Timber::context();
$context['posts'] = Timber::get_posts();
$context['foo'] = 'bar';
$templates = array( 'templates/index.twig' );
if ( is_home() ) {
use Timber\Timber;

$templates = array('templates/index.twig');

if (is_home()) {
array_unshift( $templates, 'templates/front-page.twig', 'templates/home.twig' );
}
Timber::render( $templates, $context );

$context = Timber::context([
'foo' => 'bar',
]);

Timber::render($templates, $context);
20 changes: 6 additions & 14 deletions page.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* The template for displaying all pages.
*
Expand All @@ -7,22 +8,13 @@
* and that other 'pages' on your WordPress site will use a
* different template.
*
* To generate specific templates for your pages you can use:
* /mytheme/templates/page-mypage.twig
* (which will still route through this PHP file)
* OR
* /mytheme/page-mypage.php
* (in which case you'll want to duplicate this file and save to the above path)
*
* Methods for TimberHelper can be found in the /lib sub-directory
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.1
*/

namespace App;

use Timber\Timber;

$context = Timber::context();
$post = $context['post'];

$timber_post = Timber::get_post();
$context['post'] = $timber_post;
Timber::render(array('templates/page-' . $timber_post->post_name . '.twig', 'templates/page.twig'), $context);
18 changes: 8 additions & 10 deletions search.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<?php

/**
* Search results page
*
* Methods for TimberHelper can be found in the /lib sub-directory
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.1
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
*/

use Timber\Timber;

$templates = array( 'templates/search.twig', 'templates/archive.twig', 'templates/index.twig' );

$context = Timber::context();
$context['title'] = 'Search results for ' . get_search_query();
$context['posts'] = Timber::get_posts();
$context = Timber::context([
'title' => 'Search results for ' . get_search_query(),
]);

Timber::render( $templates, $context );
Timber::render($templates, $context);
27 changes: 13 additions & 14 deletions single.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

/**
* The Template for displaying all single posts
*
* Methods for TimberHelper can be found in the /lib sub-directory
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.1
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
*/

$context = Timber::context();
$timber_post = Timber::get_post();
$context['post'] = $timber_post;
namespace App;

if (post_password_required($timber_post->ID)) {
Timber::render('single-password.twig', $context);
} else {
Timber::render(array('templates/single-' . $timber_post->ID . '.twig', 'templates/single-' . $timber_post->post_type . '.twig', 'templates/single-' . $timber_post->slug . '.twig', 'templates/single.twig'), $context);
}
use Timber\Timber;

$context = Timber::context();
$post = $context['post'];
$templates = array('templates/single-' . $post->ID . '.twig', 'templates/single-' . $post->post_type . '.twig', 'templates/single-' . $post->slug . '.twig', 'templates/single.twig');

if (post_password_required($post->ID)) {
$templates = 'templates/single-password.twig';
}

Timber::render('templates/single-password.twig', $context);
Loading

0 comments on commit e938aae

Please sign in to comment.