Warning: Table './yimaster_pras/watchdog' is marked as crashed and should be repaired query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:14:\"strict warning\";s:8:\"%message\";s:62:\"Non-static method view::load() should not be called statically\";s:5:\"%file\";s:68:\"/home/yimaster/public_html/pras/sites/all/modules/views/views.module\";s:5:\"%line\";i:842;}', 3, '', 'http://pras.net.np/blogs/guide-cck-nodereference', '', '54.158.109.89', 1490400469) in /home/yimaster/public_html/pras/includes/database.mysql.inc on line 128

Warning: Table './yimaster_pras/watchdog' is marked as crashed and should be repaired query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:14:\"strict warning\";s:8:\"%message\";s:102:\"Declaration of views_plugin_style_default::options() should be compatible with views_object::options()\";s:5:\"%file\";s:94:\"/home/yimaster/public_html/pras/sites/all/modules/views/plugins/views_plugin_style_default.inc\";s:5:\"%line\";i:25;}', 3, '', 'http://pras.net.np/blogs/guide-cck-nodereference', '', '54.158.109.89', 1490400469) in /home/yimaster/public_html/pras/includes/database.mysql.inc on line 128

Warning: Table './yimaster_pras/watchdog' is marked as crashed and should be repaired query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:14:\"strict warning\";s:8:\"%message\";s:62:\"Non-static method view::load() should not be called statically\";s:5:\"%file\";s:68:\"/home/yimaster/public_html/pras/sites/all/modules/views/views.module\";s:5:\"%line\";i:842;}', 3, '', 'http://pras.net.np/blogs/guide-cck-nodereference', '', '54.158.109.89', 1490400469) in /home/yimaster/public_html/pras/includes/database.mysql.inc on line 128

Warning: Table './yimaster_pras/watchdog' is marked as crashed and should be repaired query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:14:\"strict warning\";s:8:\"%message\";s:157:\"Declaration of views_content_plugin_display_panel_pane::options_submit() should be compatible with views_plugin_display::options_submit(&$form, &$form_state)\";s:5:\"%file\";s:128:\"/home/yimaster/public_html/pras/sites/all/modules/ctools/views_content/plugins/views/views_content_plugin_display_panel_pane.inc\";s:5:\"%line\";i:358;}', 3, '', 'http://pras.net.np/blogs/guide-cck-nodereference', '', '54.158.109.89', 1490400469) in /home/yimaster/public_html/pras/includes/database.mysql.inc on line 128
A Guide to CCK nodereference | Prashant Shrestha's Blog
  • strict warning: Non-static method view::load() should not be called statically in /home/yimaster/public_html/pras/sites/all/modules/views/views.module on line 842.
  • strict warning: Declaration of views_handler_argument::init() should be compatible with views_handler::init(&$view, $options) in /home/yimaster/public_html/pras/sites/all/modules/views/handlers/views_handler_argument.inc on line 745.
  • strict warning: Non-static method views_many_to_one_helper::option_definition() should not be called statically, assuming $this from incompatible context in /home/yimaster/public_html/pras/sites/all/modules/views/handlers/views_handler_argument_many_to_one.inc on line 34.
  • strict warning: Non-static method views_many_to_one_helper::option_definition() should not be called statically, assuming $this from incompatible context in /home/yimaster/public_html/pras/sites/all/modules/views/handlers/views_handler_argument_many_to_one.inc on line 34.
  • strict warning: Declaration of views_handler_filter::options_validate() should be compatible with views_handler::options_validate($form, &$form_state) in /home/yimaster/public_html/pras/sites/all/modules/views/handlers/views_handler_filter.inc on line 585.
  • strict warning: Declaration of views_handler_filter::options_submit() should be compatible with views_handler::options_submit($form, &$form_state) in /home/yimaster/public_html/pras/sites/all/modules/views/handlers/views_handler_filter.inc on line 585.
  • strict warning: Declaration of views_handler_filter_boolean_operator::value_validate() should be compatible with views_handler_filter::value_validate($form, &$form_state) in /home/yimaster/public_html/pras/sites/all/modules/views/handlers/views_handler_filter_boolean_operator.inc on line 149.
  • strict warning: Declaration of views_plugin_row::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home/yimaster/public_html/pras/sites/all/modules/views/plugins/views_plugin_row.inc on line 135.
  • strict warning: Declaration of views_plugin_row::options_submit() should be compatible with views_plugin::options_submit(&$form, &$form_state) in /home/yimaster/public_html/pras/sites/all/modules/views/plugins/views_plugin_row.inc on line 135.
  • strict warning: Non-static method view::load() should not be called statically in /home/yimaster/public_html/pras/sites/all/modules/views/views.module on line 842.
  • strict warning: Declaration of views_plugin_style_default::options() should be compatible with views_object::options() in /home/yimaster/public_html/pras/sites/all/modules/views/plugins/views_plugin_style_default.inc on line 25.
  • strict warning: Non-static method view::load() should not be called statically in /home/yimaster/public_html/pras/sites/all/modules/views/views.module on line 842.
  • strict warning: Declaration of views_content_plugin_display_panel_pane::options_submit() should be compatible with views_plugin_display::options_submit(&$form, &$form_state) in /home/yimaster/public_html/pras/sites/all/modules/ctools/views_content/plugins/views/views_content_plugin_display_panel_pane.inc on line 358.

A Guide to CCK nodereference

22 comments

 

Those who use drupal will probably agree that CCK(Content Construction Kit) is one of the most important modules that drupal has to offer. CCK allows us to create custom content types and add different kinds of fields to it. The power of CCK can be extended with the help of different contributed modules.

Who this article is for

This article is for those who have some experience with Drupal and are comfortable using CCK.

In this tutorial we will be exploring a very useful feature of CCK called Nodereference. The CCK nodeference helps to define a relationship among different content types. For this particular tutorial I have used two content types:

  1. Artists

  2. Album

The song content type is related to the artist content type and the album content type is related to the artist content type.

 

What you will need

  1. A Drupal 6 installation, you can download it here.
  2. CCK(Content Construction Kit) module

 

Unzip the CCK module that you downloaded to your modules directory inside sites/all/modules.

 

Enable the modules

The next thing that you need to do is enable content and noderereference in your modules page at http://example.com/admin/build/modules/list

 

Enable content which is the main cck module and also enable noderefernece,text, and option widgets.

Create your contents

First create a content type called artist. I haven't added any extra fields but you can add extra fields like artist image and so on.

Next create a content type called album. We want to relate this particular content type to the artist content type. An artist can have many albums and we want to display this relationship. The way we can do that is through nodereference. In the manage fields of the album content type add a nodereference type field. Since I want to reference this album content to the artist content I will select artist in the content type that can be references: select list.

 

In the settings page select the type of content that you want to reference in this case we want to reference the artist content type so we select artist.

 

Lets Add some content

Ok, time to add some content. I have added three artists Johnny Cash, Taylor Swift and Dixie chicks.

Now when I create a new album. I will get a select list which will display all the Artists that I have created.

I select Dixie Chick, and when I click on submit I get a link to the artist page in my album node.

 

In this way the album node Wide open spaces is now referenced to its respective artist node.

 

Enhance Node reference

The power of node reference can be felt when it is used with Views 2 Relationship. I will be writing a tutorial on that in the future. But there are ways to enhance its feature. I have found two modules that works great in conjunction with the CCK node reference.

Nodereferrer

It provides a counter part to the CCK node reference. It is sort of like a back reference. What is does it it lists all the nodes that has referenced that particular node. In our case it displays all the albums belonging to a particular artist.

To use nodereferrer download it here.

Place it in your modules directory and enable it.

Next edit your artist content type and in your manage fields add a node referrer type field.

Select the referring node and the field used to refer to the artist node.

Now u can see all the albums related to that particular artist in the artist page.

Using these you can create a Last FM type website.

Noderefcreate

Node Reference allows us to link a node to another node. But the catch is that the parent node has to exist first. Thats where Noderefcreate comes handy. Noderefcreate helps to bypass all that. With it we can reference a non-existent node.

 

So much for todays tutorial...Next time we will be discussing about the Views 2 relationship.

22 Responses to "A Guide to CCK nodereference"

Bina says:

nice article.

Anjhero says:

Nice article to kick start the blog!! way to go bro!!

Anjhero says:

this is such a nice theme!! im all jealous now :P

Prakhyat says:

Hey Bro......nice work.....Love the design of the blog.......

prashant says:

Thanks a lot bro..  :)

Good article man, well defined. Breaking the content with h3 looks pro. You will make a good blogger ;).

Let's start blogging for YIPL's site.

prashant says:

Thanks man....Ya we shud definitely start blogging for yipl's site...

hmadani says:

Nice article.
i have a question an need help. When créate the "Wide open spaces" i want to show on the liste box the title of the reference and all of the album fields.
how can i write the return array(0=>('nid','') ...,

prashant says:

I dont quite follow..can you please elaborate..

mttn says:

Nice article.

"Next time we will be discussing about the Views 2 relationship" - where is this, please?

mr.design says:

Good article, bro..
Although, in the second screenshot I think instead of album it should be - Artist.... :)

Anonymous says:

nice and clear, how would you reference an image field?

The way to do this with pure views is described on this drupal forums post

Shaun says:

Thanks for the awesome tutorial on nodereference. There is a lot of information out there for Drupal 5, but not 6. This information cuts the mustard.

Thanks for the tutorial.
But I would like to know if there is the possibility to referrer a album to more than one artist.

Thanks

Jaime says:

Thank you for the explication, exelent information, but I have a question about this module "NodeReferrer" and views, How can I add this field to one view? 'cause isn't in the option of views. Thank you again.

Anonymous says:

How can you use node reference to implement an RDB's PK and FK in Drupal 6. Since FileField Reference is not available in D6, what would be the work around.

Anonymous says:

Thank you for your legible explanation.

Anonymous says:

Hi,
Thank you very much for the tutorial, but i have a question regarding the node referrer module... I just want to display some other fields apart from the node title...... something like logo
Please help me is that can possibly done by nodereferer else give me some alternate solution

Thanks in advance

equals3 says:

Has the principle of node references changed with Drupal 7?

ata says:

Nice article prashant

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
1 + 3 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.