2

I'm aware of such modules as Relation and Entity reference but I can't figure out how I make automatic relation between nodes that depend on the user that submitted those nodes.

Site has users A, B, C ... Let's say user A submits 10 nodes. When any user clicks on any of his nodes you can see his other 9 submitted nodes in the detailed view. When you click on node submitted by user B you can see his other submitted nodes and so on. This should work automatically without manually building relations between nodes.

How do I achieve this?

Thanks a lot Ray

2
  • 2
    I think you should be able to achive this using a view that will query all nodes but the current one that has the same author. You would then have to load and execute this view in your node.tpl or perhaps node-<type>.tpl file. Commented Nov 21, 2012 at 14:13
  • I would post an answer, but Krister Andersson already nailed it, although the exact rendering mode of the view is not in scope of the question.
    – Letharion
    Commented Nov 21, 2012 at 14:49

1 Answer 1

1

I tried the following and it seems to work:

  1. Create a new block view
  2. Add a Contextual filter of type Content: Nid
  3. Add a relationship of type Content: Author (Required)
  4. Add a relationship of type User: Content authored that uses the previous relationship and is required
  5. Under Format you set Show: Content | Full Content - You must also use the User: Content authored relationship for this one

You could also change the number of related nodes that will be shown and also you might wan't to add a filter of Content: Type to restrict what kind of nodes to display. Notice that you could create a template for a specific content-type ie node--<YOUR_CONTENT_TYPE>.tpl and load and execute the view from there.

In you node.tpl file you would load this view doing something similar to:

$view = views_get_view('YOUR_VIEW_NAME');
$view->set_display('YOUR_VIEW_BLOCK_NAME');
$view->set_arguments(array($node->nid));
$view->execute();
echo $view->render();

Note I think you should specify every field you wan't to use, in other words you shouldn't use Show: Content | Full Content - because this will result in an infinite loop. I don't think this is a complete solution, but perhaps it will point you in the right direction.

If you are using fields in the view you could create a separate template named views-view-fields--YOUR_VIEW_NAME--YOUR_VIEW_BLOCK_NAME.tpl that will be used to output the actual fields.

To exclude the current node from the listing you need to modify your contextual filter.

  • Click the More button for Content: Nid and choose exclude you should also make this filter use your relationship for Content: Authored
5
  • Thanks a lot Krister. It worked. Except that I get this erro now in admin console and somethimes it apears on front end: screencast.com/t/Ing9HBjCKMU any idea how to fix this? Also in Node detail page I can see node duplicates now - the node that is opened and the same node together with user related nodes in the attached view. I believe i can exclude it by taking node ID from url but in contextual filters it seems that theres no NOT TO display option as in regular filters theres no "get content ID from url" option
    – Ray
    Commented Nov 22, 2012 at 11:48
  • @Ray - What Drupal and views version are you running? Perhaps this drupal.org/node/1556174 is related to your problem with the dom_id. I will check to see if I can find I way to exclude the current node from the view (I think I've succeeded with this before=) Commented Nov 22, 2012 at 13:46
  • I'm running Drupal 7.17 and Views 3.5, thanks for the link will try to find answers there :)
    – Ray
    Commented Nov 22, 2012 at 14:02
  • I have found the answer, I update my answer, hold on=) Commented Nov 22, 2012 at 14:05
  • Your solution is good but still Add a relationship of type User: Content authored that uses the previous relationship and is required it should be Add a Filter of type User: Content authored that uses the previous relationship and is required
    – gurukatre
    Commented May 27, 2013 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.