Referring node to each other
I had to create something for a client that involved some referring of node.
There were two types of content that needed to be referred to each other. The node type A and the Node type B.
In this particular case the user wanted to refer to node type B when editing or creating Node type A.
The Node B type could be editied but did not need a reference to A.
How is this in practise. My client has a business with multiple services. For his website he creates static pages that are available from the menus in the website.
Later on he wants to create blog. These blogs are used to inform clients and visitors of news regarding his expertise, his clients and business developments.
In this blog he want to be able to also show what service is related to the blog article. To be complete he also wahts to show on his static service webpage the blogs that have a relation to this service.
The most important part is that when selecting a service in a blog, it automatically will be refered back. This will save allot of time for the client.
The schema:
How did I manage that.
Install the following modules
- CCK (Node reference)
- Views
- Backreference
- Blog (from core)
To start setup the referring fields:
Edit Node type B (Page)
- create nodereference field (field_blog_refer)
- do NOT setup yet!! Just SAVE
Edit node type A (blog) content type
- Create nodereference field (field_page_refer)
- Select any widget type, if you have list of content use the 'autocomplete type'
- Select node type B for refered content type you want(or more)
- Select field_blog_reference (as created in your Node B type)
- Save
Now edit your Node B(Page) content type
- Edit field 'field_blog_refer'
- Select widget type (any will do, because its automatic refrence)
- Select node type A for refered content type
- Select field_page_reference (as created in your Node A type)
- Save
Thats is for the content type setup.
Now i want to be able to view teh referred content. For this I create two views blocks.
- A block where I can see the selected B(pages) nodes when creating my Node A (blog) content type (this will show on blog nodes)
- A block where i can see Node A(blogs) nodes that are referring to Node B (this will show on page nodes)
The tutorial covers only the minimalviews setup needed. Items not named, basic setup/relations etc can be edited to your liking without any problem.
|
view 1
content --> field_blog_reference standard argument --> php code (remove <?php and ?> when using code ) <?php
|
view 2
content --> field_page_reference standard argument --> php code (remove <?php and ?> when using code ) <?php
|
Now place the blocks in a region you want using the blocks menu and the vlocks will only show content on the designated pages view 1 on blog conten and view 2 on page content.
I hope it works for you.
If it doesn't leave a message.
- blog van admin
- Login om te reageren
