Created
April 16, 2015 08:14
-
-
Save tjFogarty/9358668c9e015616e674 to your computer and use it in GitHub Desktop.
WordPress + Timber example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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