【发布时间】:2017-12-10 19:47:36
【问题描述】:
我正在尝试获取每个分类选项的列表,并在每个选项下方列出使用该分类选项的记录。
这是我想要的最终结果:
家人/朋友/家
诗 1
诗 2
卡特
诗 3
诗 4
诗 5
政治
诗 6
诗 7
这是taxonomy.yml:
poems:
name: Poems
slug: poems
singular_name: Poem
singular_slug: poem
behaves_like: categories
options: { familyfriendshome: "Family/Friends/Home", cath: "Cath", politics: "Politics", observations: "Observations", whimsical: "Whimsical", other: "Other" }
has_sortorder: true
这是 contenttypes.yml
poems:
name: Poems
singular_name: poem
behaves_like: categories
fields:
slug:
type: slug
uses: name
name:
label: Title of Poem
type: text
placeholder: e.g., The Way You Look Tonight
sortname:
label: Name for Sorting
type: text
placeholder: This won't be visible on the site - it's just for sorting
date:
label: Date written
type: text
placeholder: e.g., August 2017
text:
type: html
height: 300px
#options:
#ckeditor:
#removeButtons: 'Format,Styles,Font,Outdent,Indent,RemoveFormat,Source'
listing_template: poemsTEST.twig
record_template: poemdetail.twig
taxonomy: [ poems ]
file_under: poems
recordsperpage: 300
default_status: published
这是我目前在列表模板中得到的:
<ul>
{% for poem in app.config.get('taxonomy/poems/options') %}
<li>{{ poem }}
{% setcontent allpoems = 'poems' where { options: 'cath' } printquery %}
<ul>
{% for poem in allpoems %}
<li>
<a href="{{ poem.link }}">{{ poem.title }}</a>
</li>
{% endfor %}
</li>
</ul>
{% endfor %}
</ul>
这是它产生的:
家人/朋友/家
诗 1
诗 2
诗 3
诗 4
诗 5
诗 6
诗 7
卡特
诗 1
诗 2
诗 3
诗 4
诗 5
诗 6
诗 7
政治
诗 1
诗 2
诗 3
诗 4
诗 5
诗 6
诗 7
我尝试设置选项:cath 最初只是为了看看它是否会选择正确的记录。如果我向其中添加 printquery,我会得到:
SELECT bolt_poems.* FROM bolt_poems WHERE ("bolt_poems"."status" = 'published') ORDER BY datepublish DESC LIMIT 9999
它会列出每条记录并忽略选项。
我在问不可能吗?
提前致谢
Cath
附言我以前应该注意到的东西。后端诗歌概览页面具有我想要的布局(在 taxonomy.yml 中使用 has_sortorder: true) - 分类的名称,然后是使用该分类的所有诗歌
【问题讨论】: