我的 single.twig 文件中的 post.next 和 post.prev 有问题。该查询针对自定义帖子类型,但也针对特定分类术语。存档页面显示正确的帖子,但如果我单击一个项目并进入 single.twig,下一个和上一个按钮会循环显示自定义帖子类型的所有帖子,而不仅仅是包含指定分类术语的帖子。这是 Timber 支持的东西吗?如果没有,有人可以帮我在我的functions.php中为它编写一个函数吗?
我什至尝试过覆盖默认查询。这是我的 archive.php 文件中的代码:
global $paged;
if (!isset($paged) || !$paged){
$paged = 1;
}
$context = Timber::get_context();
$args = array(
'post_type' => 'credits', //this is the CPT
'orderby' => 'menu_order',
'order' => 'ASC',
'posts_per_page' => '999',
'paged' => $paged,
/*
'meta_query' => array(
array(
'key' => 'video',
'value' => 'yes',
'compare' => '=',
)
)
*/
'tax_query' => array(
array (
'taxonomy' => 'auto_taxonomies',
'field' => 'slug',
'terms' => 'in-film-archive',
)
)
);
/* THIS LINE IS CRUCIAL */
/* in order for WordPress to know what to paginate */
/* your args have to be the defualt query */
query_posts($args);
/* make sure you've got query_posts in your .php file */
$context['posts'] = Timber::get_posts();
$context['pagination'] = Timber::get_pagination();
var_dump($context['pagination']);
Timber::render('archive-films.twig', $context);
这是我在 single.twig 文件中的代码:
<div class="post-nav">
{% if post.prev(true) != null %}
<div class="prev-film two columns"><a href="{{post.prev.link}}">{{post.prev(true).title}}</a></div>
{% endif %}
{% if post.next(true) != null %}
<div class="next-film two columns"><a href="{{post.next.link}}">{{post.next(true).title}}</a></div>
{% endif %}
</div>
我需要添加任何特定于我的 single.php 文件的内容吗?