Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Created October 2, 2018 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshfeck/cffca80358305709025f08979de85a60 to your computer and use it in GitHub Desktop.
Save joshfeck/cffca80358305709025f08979de85a60 to your computer and use it in GitHub Desktop.
Hydrogen theme template that preserves the global $post object.
<?php
/**
* @package Gantry 5 Theme
* @author RocketTheme http://www.rockettheme.com
* @copyright Copyright (C) 2007 - 2017 RocketTheme, LLC
* @license GNU/GPLv2 and later
*
* http://www.gnu.org/licenses/gpl-2.0.html
*/
defined('ABSPATH') or die;
use Timber\Timber;
/*
* The Template for displaying all single posts
*/
global $post;
$gantry = Gantry\Framework\Gantry::instance();
$theme = $gantry['theme'];
// We need to render contents of <head> before plugin content gets added.
$context = Timber::get_context();
$context['page_head'] = $theme->render('partials/page_head.html.twig', $context);
$altered_post = Timber::query_post();
$context['post'] = $altered_post;
$context['wp_title'] .= ' - ' . $altered_post->title();
Timber::render(['single-' . $post->ID . '.html.twig', 'single-' . $post->post_type . '.html.twig', 'single.html.twig'], $context);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment