获取“节点参考”的字段或全部内容

时间:2012-11-06 11:54:48

标签: php drupal drupal-7 drupal-nodes

我创建了一种内容类型:“战斗”,其中字段是“节点引用”,引用来自其他内容类型的现有内容(“事实”)。

现在,当我去了解节点:“node - battaglia.tpl.php”时,如何获取引用节点的某些字段(“fact”),或者使用它的所有内容?

(我使用Drupal 7)

1 个答案:

答案 0 :(得分:2)

尝试类似的内容:

$nids = array();
foreach($content['YOUR_FIELD_NAME']['#items'] as $key => $val)
{
    $nids[] = $val['target_id'];
}
// the referenced nodes ids are now stored inside "$nids" array.
// You can do whatever you need to do from there.
// below I try to load the node object of each nid.
$nodes = node_load_multiple($nids);

希望这有帮助......穆罕默德。

相关问题