Skip to content

Instantly share code, notes, and snippets.

View davidmaneuver's full-sized avatar

David De Coninck davidmaneuver

View GitHub Profile
{% extends 'views/base.twig' %}
{% block content %}
<h1>{{ post.title }}</h1>
{{ post.content }}
{% endblock %}
<html lang="{{ lang }}">
<head>
{{ wp_head }}
</head>
<body>
{% block content %}{% endblock %}
{{ wp_footer }}
</body>
</html>
<h1>{{ post.title }}</h1>
<p>Written by {{ post.full_name }}</p>
<?php
add_filter('Timber\PostClassMap', function(){
return [
'post' => '\Example\Model\MyPost'
];
});
<?php
namespace Example/Model;
class MyPost extends \Timber\Post {
public function full_name() {
// first_name and last_name could be ACF fields.
return "{$this->first_name} {$this->last_name}";
}
<?php
/**
* Serve 404 header whenever rendering the notound.twig template.
**/
add_filter('timber_render_file', function($template) {
if (strpos($template, 'notfound.twig')) {
status_header(404);
}
return $template;
<?php
include('common.php');
/**
* Create a list of templates Timber will look for to render.
*/
$templates = ['notfound'];
/**
<?php
/**
* Get context.
**/
$context = Timber::get_context();
/**
* Retrieve current language.
**/
<?php if ( have_posts() ) :?>
<ul>
<?php while ( have_posts() ) : the_post(); ?>
<li><?php the_title() ?></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
{% if posts %}
<ul>
{% for post in posts %}
<li>{{ post.title }}</li>
{% endfor %}
</ul>
{% endif %}