【发布时间】:2018-04-26 19:21:43
【问题描述】:
我有一个带有自定义分类法('vehicles_category')的 CPT('vehicles')
我有 4 个类别(建筑、道路、废物、其他),每个类别都有许多帖子。
我正在尝试在下面列出每个类别以及分配给它们的帖子......
Construction
Post 1
Post 2
etc
Road
Post 6
Post 9
etc
一直在与这个作斗争。
我有这个来获取帖子...
$context['vehicles'] = Timber::get_posts([
'order' => 'ASC',
'post_type' => 'vehicles',
'posts_per_page' => -1,
'paged' => $paged,
]);
这是获取类别...
$context['categories'] = Timber::get_terms('vehicle_category');
$context['posts'] = $context['vehicles'];
到目前为止,我的树枝文件中有这个...
{% for category in categories %}
{% if category.count >= 1 %}
<li>
<a href="{{site.url}}/vehicles/{{ category.slug }}">{{ category.title }}</a>
</li>
{% endif %}
{% endfor %}
但它只输出类别,因为我缺少输出帖子的位,但我尝试的一切都不起作用。
有什么想法吗? 谢谢
【问题讨论】:
标签: wordpress categories timber