【问题标题】:Timber Wordpress child menu木材 Wordpress 子菜单
【发布时间】:2017-08-21 17:24:20
【问题描述】:

我正在寻找一种方法来显示当前页面的所有子页面,类似于 wp_page_list 函数,但在 Timber (Twig) 中。

我知道我可以通过查询添加到上下文中,或者简单地将 worpdress 函数包装在一个木材函数中。

我正在努力使用的任何一种方法,并希望得到一些语法指导。

非常感谢。

【问题讨论】:

    标签: timber


    【解决方案1】:

    不确定这是多么理想,但它确实有效

    {% 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.linkitem.url。所以那将是{% if item.children and item.current %}
    【解决方案2】:

    您是否尝试在不使用 WordPress 菜单的情况下显示子页面?所以没有get_items 方法?给定页面的子页面可通过 post 对象获得,而与任何菜单功能无关。

    {% for child in post.children %}        
       <li><a href="{{ child.link }}">{{ child.title }}</a></li>
    {% endfor %}
    

    这假定您的控制器中有$context['post'] = new TimberPost();

    【讨论】:

      猜你喜欢
      • 2022-10-02
      • 1970-01-01
      • 1970-01-01
      • 2015-12-25
      • 1970-01-01
      • 2013-10-14
      • 1970-01-01
      • 1970-01-01
      • 2015-04-22
      相关资源
      最近更新 更多