Skip to main content
Timber

You are reading the documentation for Timber v1.x. Switch to the documentation for Timber v2.x.

Timber\Archives

The TimberArchives class is used to generate a menu based on the date archives of your posts. The Nieman Foundation News site has an example of how the output can be used in a real site (screenshot).

PHP

<?php
$context['archives'] = new TimberArchives( $args );

Twig

<ul>
{% for item in archives.items %}
<li><a href="{{item.link}}">{{item.name}}</a></li>
{% for child in item.children %}
<li class="child"><a href="{{child.link}}">{{child.name}}</a></li>
{% endfor %}
{% endfor %}
</ul>

HTML

<ul>
<li>2015</li>
<li class="child">May</li>
<li class="child">April</li>
<li class="child">March</li>
<li class="child">February</li>
<li class="child">January</li>
<li>2014</li>
<li class="child">December</li>
<li class="child">November</li>
<li class="child">October</li>
</ul>

Overview #

Properties #

NameTypeDescription
itemsarraythe items of the archives to iterate through and markup for your page

Methods #

NameTypeReturns/Description
__constructvoid
get_itemsarray/string

Class Methods #

__construct #

__construct( mixed $args=null, string $base="" )

returns: void

NameTypeDescription
$argsmixedarray of arguments {
$basestringany additional paths that need to be prepended to the URLs that are generated, for example: "tags"

get_items #

get_items( mixed/array/string $args=null )

returns: array/string

NameTypeDescription
$argsmixed/array/string

This class extends \Timber\Core