Drupal: Combining Taxonomy with Node Reference

Saif Sail
Scenario: You want to get the taxonomy terms associated with the node the current node references. Make sure you download the node reference url module as this will provide us a link on the referencing node types and also auto-populates a node reference field with a value from the URL

Modules required: node reference url, taxonomy and CCK

Modules configuration:
Taxonomy:
Create a new vocabulary called 'Story Tags'.
Select 'story' from the content types
And check 'Tags, Multi Select and Required'

CCK and node reference url:
Go to content/node-type/page/fields and add a new field:
Label: 'New page'
Name: 'field_new_page'
Type: Node reference
Form element: Node reference url
Then go to admin/content/node-type/page/fields/field_new_page and leave everything but the following as default: Content types that can be referenced: 'Story'

Go to content/node-type/page/fields and add a new field:
Label: 'page tags'
Name: 'field_page_tags'
Type: 'Text'
Form element: 'Select List'
Then go to admin/content/node-type/page/fields/field_page_tags and leave everything but the following as default:
Check 'Required'
Number of values: 'Unlimited'
Allowed Values PHP Code:
$values = array();
$node = node_load(arg(3));
if($node == null) {
$curr = menu_get_object();
$node = node_load($curr->field_new_page[0]['nid']);
}
if($node != null) {
foreach($node->taxonomy as $t) {
$values[$t->name] = $t->name;
}
}
return $values;

Create a new story node and publish it. Now near the links of published node is a 'new page' link. Click that and you will see a new node page form. You should now see a select list filled with all the tags you tagged the story node. Select as many as you like and complete the form and publish it.

Published by Saif Sail

Drupal enthusiast  View profile

4 Comments

Post a Comment
  • cheap christian louboutin shoes3/31/2011

    Christian Louboutin Wedges
    Christian Louboutin Sandals
    discount christian louboutin
    Christian Louboutin Online
    Christian Louboutin Sale
    cheap Christian Louboutin shoes
    Christian Louboutin Bridal
    Christian Louboutin Pumps
    http://christian-loubooutin-shoe.com

  • cc3/31/2011

    www.christian-louboutin-shoe.com

  • christian louboutin3/31/2011

    Christian Louboutin Wedges
    Christian Louboutin Sandals
    discount christian louboutin
    Christian Louboutin Online
    Christian Louboutin Sale
    cheap Christian Louboutin shoes
    Christian Louboutin Bridal
    Christian Louboutin Pumps

  • Victor2/2/2010

    Thank you for the article. It worked fine for me. But I still have a question - how do I actually get the taxonomy terms from the referenced node to be filled in in the current node's taxonomy form?

Displaying Comments

To comment, please sign in to your Yahoo! account, or sign up for a new account.