English 中文(简体)
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 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!

问题回答

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...





相关问题
Drupal Multi-language: Simple strings not translated

I m adding additional languages to a Drupal site that I m building. Getting the translation of content working is fairly easy using the Internationalisation module. Yet, simple things such as date ...

Setting up a WYSIWYG editor for Drupal site users [closed]

Looking through the Drupal contrib modules, and after a few Google searches, it becomes evident that there are any number of choices and combos available to set up a WYSIWYG editor in Drupal. I m ...

Change size of user/password login box

I don t know how to change the size of the login username/password boxes on the drupal site that I m trying to build. I m stumbling through the theming, and don t know where to find the file that ...

How does Drupal provide an edit/review/publish model?

How does Drupal support a means to update and review a website before it is published? Does it only allow you to preview a page at a time before you publish it or is there a way to create a site ...

Term for rotating header

I m looking for terminology that describes this behavior: The header of a web-page contains a different image every time you visit it. Update: It is not an advertisement, but images related to the ...

Has anyone checked out Drupal 7? [closed]

Has anyone checked out a copy of Drupal 7 yet? What do people think? I m pretty excited about the PDO and all of the designers I work with a very excited about the new admin interface/structure. Do ...

热门标签