-1

我是 Twig 的新手,我希望通过在我的索引页面上选择的博客标签来显示我的工艺 cms 中的所有文章。

我的索引页面上有一个 for each 循环来显示所有文章,但我希望只显示带有特定标签的文章,该标签已添加到工艺 cms 中的每篇文章中。

4

1 回答 1

0

只需.relatedTo()在查询您的博客文章时使用。这就像魔术一样。

https://docs.craftcms.com/v3/relations.html#the-relatedto-parameter

例如:

{% set category = entry.blogCategory.one() %} // this will be the field name of your tag

{% set posts = craft.entries()
    .section('blogPosts') // the name of your section
    .relatedTo(category) // the category object
%}
于 2019-05-12T21:09:57.413 回答