【发布时间】:2020-09-19 10:21:08
【问题描述】:
我一直在使用 Timber 来获取帖子列表。它工作正常,但我需要像这样“按日期排序”:
= 1 月 2 日 = 发布 5 帖子 4 = 1 月 1 日 = 帖子 3 帖子 2 位置 1
WordPress 函数 the_date() 可以做到这一点,但我无法使用 Timber 获得相同的结果。 the_date 返回 null
索引.php
$context = Timber::context();
// $context['posts'] = new Timber\PostQuery();
$context['posts'] = Timber::get_posts(); // both doesn't work
$templates = array( 'archive.twig', 'index.twig' );
Timber::render( $templates, $context );
存档.twig
<div class="s-archive__posts-list">
{% for post in posts %}
{{ the_date() }} // function registered via $twig->addFunction( new Timber\Twig_Function( 'the_date', 'the_date' ) );
{{ fn('the_date') }} - doesn't work too. I was guessing, maybe, fourth param of this function the case (echo) but it's not {{ fn('the_date', 'M, Y', '', '', false ) }}.
{% include 'content/content-archive.twig' %}
{% endfor %}
</div><!-- /s-archive__posts-list -->
我必须做些什么才能使其按预期工作?
更新 它适用于
$context['posts'] = Timber::query_posts();
【问题讨论】:
标签: timber