Drupal 6:从节点引用类型获取特定字段

发布于 2024-09-03 15:53:58 字数 520 浏览 3 评论 0原文

我是一个 drupal 新手...

<?php print $node->field_date[0]['view']; ?>

我可以获取自定义创建的 CCK 字段的值并显示在 tpl.php 文件中,如上所述...这很好。

我的问题是如何获取节点引用字段的内字段?例如,我有一个事件内容类型,并且我已经定义了位置的节点引用(标题、地址、img 等)。当我编写下面的代码时,它会显示所有位置内容;

<?php print $node->field_location[0]['view']; ?>

但我只需要从此位置内容类型获取地址字段。像下面这样的东西会很棒 :D 但不起作用;

<?php print $node->field_location[0]['field_address']['view']; ?>

那么如何才能得到呢?感谢非常有帮助!多谢!

I'm a drupal newbie...

<?php print $node->field_date[0]['view']; ?>

I can get the custom created CCK fields' value and display in tpl.php files as above... that's fine.

my question is how can I get the Node reference fields' in-fields? for example, I have an event content type, and I have defined Node Reference for Location (title, address, img, etc.). When I write the code below, it displays all location content;

<?php print $node->field_location[0]['view']; ?>

but I need to get only address field from this location content type. sth like below would be great :D but not working;

<?php print $node->field_location[0]['field_address']['view']; ?>

so how can get that? appreciate helps so much! thanks a lot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

森末i 2024-09-10 15:53:58

您应该检查/转储 $node->field_location 数组的内容。我现在手头没有测试安装,所以我不能肯定地说,但我希望至少引用的节点 id ('nid') 应该在该数组中的某个位置。这样,您就可以执行node_load($nid),它返回完整的节点对象,从而提供对字段的访问。

(如前所述,我不确定,但字段数组可能也已经包含整个节点对象,从而使您无需显式加载它。)

You should inspect/dump the content of the $node->field_location array. I do not have a test installation at hand right now, so I can't say for sure, but I'd expect that at least the referenced nodes id ('nid') should be in that array somewhere. With that, you can do a node_load($nid), which returns the full node object, thus providing access to the fields.

(As said, I'm not sure, but the field array might already contain the whole node object as well, saving you from the need to load it explicitely.)

痞味浪人 2024-09-10 15:53:58

$node->field_location[0]['view']; 返回在内容类型定义的显示字段部分中定义的节点。这可能对你有利。您可以欺骗它:为该节点使用“Teaser”显示,并自定义节点“Teaser”显示以满足您的需求。只是一个想法。

如果这对您不起作用,您将需要单独加载节点。您可以使用 $node->field_location[0]['nid']; 来获取节点 ID,因此您最终会得到类似这样的结果:

node_load($node->field_location[0]['nid'])->field_address[0]['view']

我不确定这是如何执行的。 ..

The $node->field_location[0]['view']; returns the node as it was defined in the Display Fields section of the content type definition. This might work for your advantage. You can trick it: use a Teaser display for that node and customize the node Teaser display to fit your needs. Just a thought.

If that doesn’t work for you, you will need to load the node separately. You can use $node->field_location[0]['nid']; to get the node ID, so you will end up with something like this:

node_load($node->field_location[0]['nid'])->field_address[0]['view']

I'm not sure how this performs...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文