Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress + Timber example
<?php
/**
* Template Name: Overview
*/
if (!class_exists('Timber')){
echo 'Timber not activated. Make sure you activate the plugin in <a href="/wp-admin/plugins.php#timber">/wp-admin/plugins.php</a>';
return;
}
$data = Timber::get_context();
$post = new TimberPost();
$data['post'] = $post;
$args = array(
'post_type' => 'custom-post-type',
'orderby' => 'post_title',
'order' => 'ASC',
'post_status' => 'publish',
'posts_per_page' => -1
);
$data['posts'] = Timber::get_posts($args);
Timber::render('overview.twig', $data);
{% extends 'base.twig' %}
{% block content %}
<ul class="o-list--basic">
{% for item in posts %}
<li>
{% if item.get_field('some_image') %}
{% set item_image = item.get_field('some_image') %}
{% else %}
{% set item_image = 'http://placehold.it/300x300' %}
{% endif %}
<img src="{{ item_image | resize(300, 300) }}" alt="">
{% if item.description %}
<p>{{ item.description | excerpt(90) }}</p>
{% endif %}
<ul class="o-list--basic">
{% for child in item.children() %}
<li>
<a href="{{ child.get_link }}">{{ child.title }}</a>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment