我想寻求关于使用Twig的Wordpress中继器内的中继器的帮助。服务部分显示正确,但服务部分中的功能部分没有显示。
这是Wordpress ACF的屏幕截图。Click Me
下面是我目前正在使用的代码。请给我建议。谢谢!
{% 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 %}发布于 2018-12-02 23:45:34
正如ACF Integration Guide所说,当您尝试访问嵌套的中继器字段时,不应再次使用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 %}发布于 2018-11-15 15:40:02
我以前从来没有做过树枝,但快速搜索一下就找到了一些东西。将内部中继器更改为:
{% for feats in services_ist.get_field('services_feat') %}
<p>{{feats.feat_title}}</p>
{% endfor %}这样,第二个中继器知道它是来自第一个中继器的孩子,而不是到帖子的直接孩子。
https://stackoverflow.com/questions/53302637
复制相似问题