Hi,
I'm not sure how to do this and can't find much info to help me, probably searching with the wrong terms as I think people have done this before :)
I have a series of nodes which have a cck field with a select widget with a couple of options (eg. bike, car, plane).
Now what I would like to do is to show a view in a block which loads a title list of nodes that have the same selected option for that cck field.
I have created a view that takes this CCK field value as an argument.
But how do I implement this view as a block so that it takes the CCK field value of the current node as the argument?
Thanx for the help!
Comments
Comment #1
bartezz commentedDUH!
Was actually an easy fix... guess I need some sleep!
Funny thing, tyring something for hours without results and then after posting here I fix it within minutes.... happens to me a lot!
Anyhow, here's my solution;
As I said I added the CCK filed as an arugment.
Within the sttings of this argument I checked [Provide default argument] under [action to take if argument is not present]
Then added php code after checking [PHP code] under [Default argument type];
That did it :D Hope it helps others...
Cheers
Comment #2
brianbrarian commentedThank you! Exactly what I needed. Works perfectly.
Though it took me a little while to figure out I had to substitute 'nid' for 'value' to display nodes that have the same value the current node has in a node reference field.
And then I added a second argument to prevent the current node from being listed in the view, as described here:
http://drupal.org/node/131482#comment-1173842
Thanks again.
Comment #3
jkomenda commentedThank you so much for this! I'd not realized that 'field_cckfieldname' was the CCK name, and that ['nid'] could be ['value'].
Comment #4
nodecode commented@Bartezz: Freaking brilliant! I've been struggling with this and the tutorials on Views 2 Arguments are terrible. You saved my sanity, way to go!
@brianbrarian: Also freaking brilliant! I see Bartezz's solution and *BAM* you've already connected the next piece of the puzzle that i needed to make it work.
Thank you! :)
Comment #5
bartezz commentedAlways good to read it helped someone!
Cheers
Comment #6
techypaul commentedThanks for popping back to update this, I needed it.
Comment #7
deng17 commentedI followed exactly what Bartezz did. What I wanted is when viewing a specific node, it will show nodes with the same value in "field_series"
It worked perfectly through Panels by specifying "Node Title" in the context BUT it only works for only one node (which is a parent node). All its child nodes also have the same value in that cck field.
If I display it as a normal block (not the Panels like above), it doesn't show up at all.
Comment #8
bartezz commentedNo experience with panels whatsoever... but it's logical that it'll only work with the parent node:
Try it with path turned of, you'll see that the second argument in the path (0 based count, so nid is arg(1) ) will be the id of the parent node. For instance (node/123).
Not sure if this solution will work for you, sorry.
Cheers
Comment #9
deng17 commentedSorry for being a noob but I don't know how to turn the path off. How will I do that?
I tried creating a node with the same value in "field_series" also set it as a parent node.
I thought that the block would work with the parent node but it didn't. It only worked for the first node I created with that value in "field_series". That first node is also a parent node.
Comment #10
bartezz commentedPath module that is... disable it under admin/build/modules/list... if you have enabled it in the first place ofcourse. Again I have no experience with panels whatsoever.
What do your urls look like? Something like node/123 or something like example.com/about-us?
But again, I think this solution might not work with panels, maybe some one else could share a light in this?
Cheers
Comment #11
deng17 commentedmydrupalsite/custom-url
I'm using Pathauto module. Hmm I think I can't disable my path module since I'm using it.
Nevermind the panels...the block also displays the same result.
Comment #12
deng17 commentedFinally I had it working after reading how arguments work.
I used nid before so it's reading from the node id itself. But by using 'value', it will read from the value of the cck field.
Thanks. I was just confused with the one who posted a modified code XD
Comment #13
naero commentedThanks for sharing this! When I used this piece of code tonight, I had to make sure that on my content pane view I changed "Argument input" (under Pane Settings) to "No argument".
To pass the value of the term ID, I used:
Comment #14
jeroen87 commentedyou've made my day ! views 2 with the arguments is a bitch but thanks to you i finally got it right :D
thanks!!!!
PS shouldn't this kind of code be more documented because I found many users who are looking for it?
Comment #15
Zehrious commentedhow can I use this same method to display nodes within a certain price range of $node->field_price[0]['value']?
Comment #16
gberm commentedHow would this work if I wanted to use two different node types. I have two different node types with the same cck field and would like to display all of the nodes of the other type that have the same field.
Any help would be greatly appreciated.
Thanks
Comment #17
drupalfan81 commentedBeautiful!! I have been wanting to do this for some time now, can't believe how easy it was. I have listings on my website and I wanted to show nearby listings based on a field in that node. Works perfectly! Thanks so much!
Comment #18
kdump commentedHas anyone got this working under D7.12? thanks.
Comment #19
1mundus commentedAlso looking for a solution for D7. The suggestions from here don't work unfortunately.
Comment #20
pedrofsv commentedFor Drupal 7, add the CCK field as Relationship, then add Content:Nid as Contextual Filter with that relationship assigned. Choose [Provide default argument] -> [PHP code] and type:
Source: http://drupal.org/node/370227 and hours of craziness ;P
If you want to hide the current node from the view, just add another Content:Nid as Contextual Filter, check [Provide default argument], select [Content id from url] and, at the bottom of the window, under [More] link check [Exclude].