Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有 postID,我需要使用 get_the_category()。正在做 :
{{ function('get_the_category', event_id) }}
这只返回字符串“Array”,但我需要第一个类别。我需要类似的东西:
{{ function('get_the_category[0]', event_id) }}
Timber 有一种get_terms获取附加到帖子的术语的方法,您可以将其与 Twigfirst过滤器结合使用以仅获取第一个术语:
get_terms
first
{{ post.get_terms('category')|first }}
最后,我使用了这种方式:
{{ function('get_the_category_list', '', '', event_id) }}
这给了我完整的类别列表,但我不得不用 CSS 隐藏其余的类别。肮脏的。