【发布时间】:2016-04-18 21:17:51
【问题描述】:
我正在尝试使用 Timber (Twig) 从另一个页面访问 ACF 数据以显示在另一个页面上。
“关于”页面中的 ACF 名称为 the_unstrung_hero (id = 7)。
page-home.php:
<?php
$context = Timber::get_context();
$post = new TimberPost();
$about_page_id = 7;
$about = new TimberPost($about_page_id);
$about->acf = get_field_objects($about->ID);
$context['post'] = $post;
Timber::render( array( 'page-' . $post->post_name . '.twig', 'page.twig' ), $context );
在 page-home.twig 内:
<p>{{ acf.the_unstrung_hero|print_r }}</p>
这只是许多人的最后一次组合尝试。坦率地说,我只是没有得到任何东西(PHP 不是我的强项)...您的帮助将不胜感激。
【问题讨论】:
-
您是否尝试过使用 acf 字段 id 而不是名称“the_unstrung_hero”?
-
如何获取 ACF 字段“ID”?谢谢
-
在添加/编辑 ACF 字段(字段组)时,单击“屏幕选项”,您将看到一个复选框“字段键”。检查并且您将能够在字段左侧看到“字段键”(或我使用的 ID)。
-
我尝试过字段键 - 让我感到困惑,因为你说的是“字段 id”。
-
你可以试试这个
the_field('the_unstrung_hero',7);