Skip to content

Instantly share code, notes, and snippets.

@joshfeck joshfeck/single.php
Created Oct 2, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.