Drupal 6: getting particular fields from Node Reference types
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 ha开发者_如何学Gove 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!
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.)
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...
精彩评论