Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rework of PHP files. #152

Merged
merged 6 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 7 additions & 8 deletions 404.php
Original file line number Diff line number Diff line change
@@ -1,13 +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( '404.twig', $context );
Timber::render('404.twig', $context);
50 changes: 25 additions & 25 deletions archive.php
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
<?php

/**
* The template for displaying Archive pages.
*
* 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
*
* Methods for TimberHelper can be found in the /lib sub-directory
* Learn more: https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.2
*/

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

use Timber\Timber;

$context = Timber::context();
$templates = array('archive.twig', 'index.twig');
Levdbas marked this conversation as resolved.
Show resolved Hide resolved

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

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

Timber::render( $templates, $context );
Timber::render($templates, $context);
26 changes: 16 additions & 10 deletions author.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
<?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();
$title = false;
if (isset($wp_query->query_vars['author'])) {
$author = Timber::get_user($wp_query->query_vars['author']);
$title = 'Author Archives: ' . $author->name();
}
Timber::render( array( 'author.twig', 'archive.twig' ), $context );

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

Timber::render(array('author.twig', '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();
29 changes: 16 additions & 13 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( 'index.twig' );
if ( is_home() ) {
array_unshift( $templates, 'front-page.twig', 'home.twig' );
use Timber\Timber;

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

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

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

Timber::render($templates, $context);
22 changes: 7 additions & 15 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( 'page-' . $timber_post->post_name . '.twig', 'page.twig' ), $context );
Timber::render(array('page-' . $post->post_name . '.twig', 'page.twig'), $context);
20 changes: 9 additions & 11 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/
*/

$templates = array( 'search.twig', 'archive.twig', 'index.twig' );
use Timber\Timber;

$templates = array('search.twig', 'archive.twig', '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);
23 changes: 11 additions & 12 deletions single.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?php

/**
* 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;

use Timber\Timber;

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

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