Created
July 15, 2017 19:38
-
-
Save gpbeer/d36c994f739f34dc49cda2be7d516811 to your computer and use it in GitHub Desktop.
Timber Taxonomy term list
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 | |
$templates = ['views/pages/archive.twig']; | |
$context = Timber::get_context(); | |
$context['title'] = 'Archive'; | |
// If is Tax 'Type' | |
if (is_tax('type')) { | |
// We pass the title | |
$context['title'] = single_cat_title('', false); | |
$type = new \Timber\Term( get_queried_object() ); | |
// Pass the context | |
$context['type'] = $type; | |
// Type children | |
$type_children_args = array( | |
'parent' => get_queried_object_id(), | |
'taxonomy' => get_queried_object()->taxonomy, | |
'hide_empty' => 0, | |
); | |
// We use get_terms in order to display children hierarchical order | |
$context['type_children'] = Timber::get_terms($type_children_args); | |
} | |
$context['posts'] = Timber::get_posts(); | |
Timber::render($templates, $context); |
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_side %} | |
{% if type %} | |
<h1>{{ type.name }}</h1> | |
<p>{{ type.description }}</p> | |
{#Children Method 1k#} | |
{% if type.children %} | |
<ul> | |
{% for term in type.children %} | |
<li> | |
<a href="{{term.link}}">{{term.title}}</a> | |
<p>{{ term.description }}</p> | |
</li> | |
{% endfor %} | |
</ul> | |
{% endif %} | |
{% endif %} | |
{#Children Method 2 hierarchical#} | |
{% if type_children %} | |
{% for term in type_children %} | |
<article class="block-white" id="{{ term.slug }}"> | |
<h2> | |
Term : <a href="{{ term.link }}"> {{ term.name }}</a> | |
</h2> | |
<p> | |
{{ term.description }} | |
</p> | |
</article> | |
{% endfor %} | |
{% endif %} | |
{% for post in posts if not type_children %} | |
<article class="block-white" id="{{ post.slug }}"> | |
<h2> | |
POST : <a href="{{ post.link }}"> {{ post.name }}</a> | |
</h2> | |
</article> | |
{% endfor %} | |
{% endblock %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment