Timber\Archives
The Timber\Archives
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
$context['archives'] = new Timber\Archives( $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 #
This class extends Timber\Core
Properties #
Name | Type | Description |
---|---|---|
$base | string | |
$items | array | The items of the archives to iterate through and markup for your page. |
Methods #
Name | Return Type | Summary/Returns |
---|---|---|
__construct() | Build an Archives menu | |
array or string | Gets archive items. | |
items() | array or string |
Class Methods #
__construct() #
Build an Archives menu
__construct( array $args = null, string $base = '' )
Name | Type | Description |
---|---|---|
$args | array | Optional. Array of arguments.
|
$base | string | Any additional paths that need to be prepended to the URLs that are generated, for example: "tags". Default ''. |
get_items() #
Gets archive items.
DEPRECATED since 2.0.0, use {{ archives.items }}
instead.
get_items( mixed $args = null )
Returns: array|string
items() #
items( array|string $args = null )
Returns: array|string
Name | Type | Description |
---|---|---|
$args | array or string | Optional. Array of arguments. |