中继器内的Twig Wordpress中继器



我想寻求有关Wordpress上使用Twig的中继器中的中继器的帮助。服务部分显示正确,但服务部分中的功能部分没有显示。

这是Wordpress ACF的屏幕截图。点击我

下面是我目前正在使用的代码。请告知。非常感谢。

{% extends "page.twig" %}
{% block additional %}
<div id="page-services">
  <section id="services">  
    <div class="row small-up-1 large-up-1">
    <div class="small-12 medium-11 large-9 columns small-centered">
    <div class="services-grid animated fadeIn wow">
    <p align="center">
      {{post.services_desc}}
    </p>
</div>
</div>
</div>
<div class="line centered"></div>
</div>
<center>
<div class="row">
<div class="small-12 medium-11 large-9 columns small-centered">
<div class="features-header animated fadeIn wow">
{% for item in post.get_field('services_ist') %}
  <div class="column services">
    <h2 class="capitalize bold">
      {{item.services_title}}
    </h2>
  {% if item.services_subtitle %}
    <h4 class="subtitle">
      {{item.services_subtitle}}
    </h4>
<div class="line thin"></div>
  {% endif %}
  {% if item.services_content %}
    <div class="description">
      {{item.services_content}}
      <br><br>
    </div>
  {% endif %}
{% if feats.services_feat %}
  {% for feats in post.get_field('services_feat') %}
    <p>{{feats.feat_title}}</p>
  {% endfor %}

  {% if feats.feats_desc %}
    <h4 class="feats description">
      {{feats.feats_desc}}
    </h4>
  {% endif %}
{% endif %}
  </div>
{% endfor %}
</center>
</div>
</div>
</div>
  </section>
</div>
{% endblock %}

正如ACF集成指南所说,当您尝试访问嵌套中继器字段时,不应该再次使用get_field()

当您在外部ACF字段上运行get_field时,内部的所有内容都可以被遍历。您可以通过item_outer.inner_repeater 引用嵌套字段

所以不使用:

{% for feats in post.get_field('services_feat') %}

您应该使用:

{% if feats.services_feat %}
    {% for feats in feats.services_feat %}
        <p>{{ feats.feat_title }}</p>
    {% endfor %}
    {# … #}
{% endif %}

我以前从未做过trick,但快速搜索让我有所收获。将内部中继器更改为:

  {% for feats in services_ist.get_field('services_feat') %}
    <p>{{feats.feat_title}}</p>
  {% endfor %}

通过这种方式,第二中继器知道它是来自第一中继器的子中继器,而不是直接子中继器。

最新更新