【发布时间】:2017-08-21 17:24:20
【问题描述】:
我正在寻找一种方法来显示当前页面的所有子页面,类似于 wp_page_list 函数,但在 Timber (Twig) 中。
我知道我可以通过查询添加到上下文中,或者简单地将 worpdress 函数包装在一个木材函数中。
我正在努力使用的任何一种方法,并希望得到一些语法指导。
非常感谢。
【问题讨论】:
标签: timber
我正在寻找一种方法来显示当前页面的所有子页面,类似于 wp_page_list 函数,但在 Timber (Twig) 中。
我知道我可以通过查询添加到上下文中,或者简单地将 worpdress 函数包装在一个木材函数中。
我正在努力使用的任何一种方法,并希望得到一些语法指导。
非常感谢。
【问题讨论】:
标签: timber
不确定这是多么理想,但它确实有效
{% for item in menu.get_items %}
{% if item.get_children and post.link == item.url %}
<ul class="jumbo-menu {{ post.slug | replace({'-data':''})}}">
{% for child in item.get_children %}
<li><a href="{{child.get_link}}">{{child.title}}</a></li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
【讨论】:
item.current,而不是比较post.link 和item.url。所以那将是{% if item.children and item.current %}。
您是否尝试在不使用 WordPress 菜单的情况下显示子页面?所以没有get_items 方法?给定页面的子页面可通过 post 对象获得,而与任何菜单功能无关。
{% for child in post.children %}
<li><a href="{{ child.link }}">{{ child.title }}</a></li>
{% endfor %}
这假定您的控制器中有$context['post'] = new TimberPost();。
【讨论】: