By Trunkhorn on
I would like to create a block on a node that shows a list of all the other nodes that have the same value in their node reference field as the current node has in its node reference field. Does anyone know how to achieve this?
Comments
.
I'm sure this can be done with more than one way with some php coding in your block, but i cannot think a way to send "dynamically" filters to the view, (something like the arguments) when the view will be executed.
anyway
I think these modules are related with your requirements: node relationships module and or Reverse Node Reference
ReliabilityConsistencyFeedbackI finally figured it out with
I finally figured it out with some trial and error madness.
The only argument needed is
Content: Node Reference > Provide default argument > PHPCode
and in that field use this:
In that case "field_referencefield" will be whatever name you gave your node reference field when creating it in the "content types" admin.
So after you get that part of the view correct, be sure to filter it by content type if you need to.
Whether that code is solid or not I have no idea as I am not a coder, so maybe someone can check it at some point.
Also don't forget to remove the currently displayed node from the list by using a second argument:
Node: Nid > Provide default argument > Node ID from URL
And then at the bottom check off the box that says "Exclude the argument".
Multiple values
Nice work, it's possible make argument when "field_referencefield" has multiple values?
Thank you
I have a similar scenario to yours. I used your argument handling code and it worked perfectly.
Passing node reference works
I've been going through some trial and error madness myself and finally came upon this. It works a treat! - Thanks...
My next task is to figure out how I can have a page that has the latest of these. It doesn't seem to display the full node (missing the part that uses the reference argument). This is probably due to the fact that it is a node that sits within a node.
+
+
Thanks
It was nice and elegant, and it helped.
Exactly the code I was
Exactly the code I was looking for - thank you.
You just made my day!
Works very nicely thanks so much.
Nicolas
-------------------------
I feel like I want to
I feel like I want to bookmark this thread for later, but I don't think I understand what the use case is to be honest.
On my site I'm displaying all fields with the same node reference field info by just adding a single argument on the node reference... Does this provide some other functionality to that? I understand it's clearly stated above, but I can't understand the difference between what I'm doing and what you're doing...
For example I have a Sites node content type that has a "network" node reference field, and I save a network name into that field.. So using an argument on field_site_network with display all values I can display all Sites where network = whatever. I make it show up using a "node content" view via DisplaySuite, but I could put it in a block if I wanted I suppose.
My particular user case
I have a content type called topics and other content types like images, videos, stories that use a node reference field to establish parent child relationships with the topics. In the topic pages I display images, videos and stories that are referenced to that topic. On the image, etc. themselves I display a "topic card" with some fields of the topic/s and now with the argument from @Trunkhorn I can display other images from the same topic in a block.
I was trying this before:
but it didn't work
Nicolas
-------------------------