I've been using drupal for a few months now and think I've got most things under control (theming, content types and basic setup of views). However, I've not really worked on relating nodes.
I've just created two content types:
1) Person. Basically just some textfields. No references here.
2) ContentPage. A normal page but with a node-reference to the Person content type. Here I've godt "unlimited" number of values.
For different reasons I don't want the ContentPage template to render the Person-teasers. What I want is to create a view that provides a block for use on every page.
When viewing a page where Persons are referenced I want the block to automatically render the teasers of the selected persons.
In my mind this should be easy - but I've found out that it is not (for me). I can easily render all Persons (by filtering node.type). But something must be wrong about my way of thinking. It must be something like: All Person-id's matching the current node's 'referenced Persons' array. But for some reason the views interface doesn't make sense in this way to me - I've tried everything it seems...
Comments
_
I've not tried it, but there should be a filter available for your node reference field (it would be in the 'content' category.
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
Thanks for your quick
Thanks for your quick response. Your suggestion, however, doesn't seem to do the trick.
If I select the reference field in filters all I can do is select an operator (is one of, all of, none of) and the contact persons already in the database. What I need should be something like: 'is one of' the current node's referenced persons. This, I think, is something different from your suggestion - if I understand it correctly?
_
The nodereference / nodereferrer relationship always makes my brain swim, lol. Usually I get what I need by poking around and trying everything I can think of, but then I can never describe to anyone how to recreate what i've done, lol.
Perhaps what your looking for is the http://drupal.org/project/nodereferrer module. Unfortunately its not ready for d6 yet-- but there is an issue in the issues queue with a patch as well as a comment with instructions for how to recreate that functionality directly with views. Might be worth a look.
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
Yes - I think I've tried
Yes - I think I've tried everything in my imagination already. I'm afraid I have to do some sort of php-code argument handling which isn't really something I know about. It must be possible without using another module as the information IS somewhere in the database (the "foreign" node knows that it is related to the current node)
Any tips will be appreciated.
_
php argument handling is located in the configuration options of the argument you add. That is, once you add an argument in views2, you'll be presented with a list of options for that argument. Choose 'provide default argument' then 'php code', then you'll be presented with a text box to which you can add your argument handling code.
Also, i found the comment in the nodereferrer issue that describes how to create the functionality with views2: http://drupal.org/node/259837#comment-1162961.
hope that helps some....
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
Found different solution (see reevos comment)
I appreciate your help. I find php argument handling very difficult. The solution reevo describes below gave me the results I was looking for. But thank you for your suggestions.
Try:
* Create a node view, row style: Fields
* Add Node: nid as your argument - this should be the nid of your ContentPage
* Add your Node reference as a field, Label: none, Format: teaser
I haven't tested this out as a block, but it returned the teasers for a node's referenced nodes when I tested the view.
Thanks!
Oh boy - this works! I think I've tried 1000 different things but it never came to my mind to add node-ref as a field. I really appreciate your help reevo! Thanks.
Very odd.
The solution described above DID "work" for me.
Seems pretty limited though, and I would have thought this was the most basic implementation of relationships.
Wouldn't we want to add a relationship with the node reference and then use that relationship with the node id argument?
Works enough.
_
I'm not sure I understand your question-- node relationships are anything but limited.
reevo This works great. My
reevo
This works great.
My referenced node has an image with it, how can I display the image rather than the node title, body or teaser? If I make the node reference excluded from display, and add in the image field, they don't show.
Thanks
Glenn
Glenn
THECA Group
Bump Thanks Glenn
Bump
Thanks
Glenn
Glenn
THECA Group
Hmmm..
I can't see a way of doing this without some coding, but then my knowledge of Views is mostly limited to D5 / Views 1, so someone else may be able to suggest something more elegant.
For simplicity, let's say we have 2 content types: Parent & Child. Parent contains the node reference to Child, and Child has a title, body and image, but in this instance we just want to show the image.
My view - let's call it "myview" - is a Node view, Row style: Node, Build mode: Teaser. It lists Parent nodes.
node-parent.tpl.php:
Worked!
I have spent far too much time trying to set up a node reference "relationship," but all that I needed to do was add the field? This worked and is much simpler than I would have suspected. Thanks reevo!
i've been looking for it for
i've been looking for it for hours, and i never noticed that option. many thanks
subscribing
subscribing
Here is my method (I am using
Here is my method (I am using Panels to show a node but I think this will also work for normal node pages):
I have two content types, say: Person, ContentPage. I want to show list of referenced Persons on a ContentPage node.
1. Created a View.
2. Added a filter: Content type: Person
3. Added any fields that I wanted to show for Person.
4. Added an argument: Content: Person (which is the name of the CCK reference field of the ContentPage content). Selected Provide Default Argument: Node ID from URL
5. Added a Block display to this view.
6. Adjusted other settings as desired...
7. Saved the view.
Then I added this block to the node pages. In my case I have done this within a panel page content. You can also add the block to any region on the normal blocks page (admin/build/blocks).
Now this block shows the list of referenced "Person"s on each "ContentPage" node.
Hope this helps...
Thanks, it was that i needed
Thanks, it was that i needed too!
brilliant! thanks alot for
brilliant! thanks alot for that
I needed to make a block that
I needed to make a block that would list only nodes that are referenced from the current one. In my case it was a list of related services at a blog post page.
Here's what I did:
- add relationship > pick Content: node reference > tick "Require relationship"
- add argument > pick Node: Nid, do NOT use a relationship; select "Provide default argument", then "Node ID from URL"
- add field > Node: Title, use a relationship
- add filter > pick Node: Type = {referenced type}, use a relationship
Voila! Check if it works correctly by trying referencing node's ID as argument in the preview box.
Below is my view, exported:
Thanks!
worked for me.
-.-
thank you
Thank you very much. Great
Thank you very much. Great man, _sparrow_ =)
Indeed I'm great.
Indeed I'm great.