I wonder if there is an easy way to display a link to the parent node when displaying a child node.
In my case, I would like this link to be displayed in a view block (displayed on every node with hierarchy enabled). It found it easy to do when displaying the children list, but I did not find out how to display the parent (if any). Help greatly appreciated on this simple issue !
Regards.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | nh-parent-error.png | 55.67 KB | ansorg |
Comments
Comment #1
ronan commentedThere is a view field option in node hierarchy called 'Node Hierarchy: Parent' which allows you to link to the parent. Create a view which only has that field in a list. Add the Node ID argument to the view and use the 'Argument Handling Code' to pass the node id of the current node to the view (http://drupal.org/node/70145#comment-1094325)
It's a bit roundabout but it should work.
Comment #2
chapo commentedThanks a lot for your answer. It works.
Comment #3
ablewave commentedGot it working, but is there any way to theme this better? right now i just get "Parent Node:" then the link.
Comment #4
andreiashu commented@ablewave: you should be able to override the output of that field in the views UI. Also for themeing you should look at the Information link provided by Views
Comment #5
m.sant commentedronan wrote: "There is a view field option in node hierarchy called 'Node Hierarchy: Parent' which allows you to link to the parent. Create a view which only has that field in a list. Add the Node ID argument to the view and use the 'Argument Handling Code' to pass the node id of the current node to the view (http://drupal.org/node/70145#comment-1094325)"
How do I pass the node id of the current node to the view?
I have tried the following line, but it didn't work:
$args[0] = (int)$node->nid; return $args;
Regards
Comment #6
m.sant commentedbump
Comment #7
Renee S commentedTypecasting is unnecessary, and you only want to pass the ID, not the whole arguments array; that might be the problem. Use drupal's arguments, they contain the path with the node id as the second argument (if it's a node). This should do it:
@andrereiashu: The problem is that there is no way to get rid of the label, it shows up and can't be overridden.
Comment #8
scroogie commentedThe use of the arg() function is not advised. As arg() uses $_GET['q'] it probably won't work if your node uses a path alias, because q won't contain the node it. Just a
should be enough.
Comment #9
andreiashu commented@scroogie @#8: afaik $_GET['q'] always contains the aliased path 'node/nid' instead of 'articles/article-name.html' for example.
But yeah, I also think that where it is possible avoid the use of arg because it is ugly :)
Comment #10
Renee S commentedYeah, andreiashu is right - arg() always returns the non-aliased path. BUT the handbook recommends against using it, and use when possible named arguments in menu callback functions. You learn something new every day :) My brain must have frozen - of course $node is available there to use. D'oh!
Comment #11
ansorg commentedhello,
using Node Hierarchy 6.x-1.x-dev (2009-Feb-28)
I try to use this method to show parents on my NH nodes. But I run into the Issue you can see on the attached screenshot: Depending on whether I view the node in "View" mode or any of the others like "dev load" or "properties" (File framework nodes) I get different parent.
The parent shown in "View" mode is wrong (it's one level too far up in the hierarchy). The parent shown in the other view mode is the correct one.
The parent link is shown in a block that is a view utilizing the "Node Hierarchy: Parent" as described in this topic
Any ideas what might be wrong on my end and how to fix it?
thanks
Comment #12
ronan commentedansorg: I believe this is being caused by the same issue as #461544: menu_get_object returns wrong node on children nodes which is now fixed in dev. Let me know if the latest dev works.
Thanks
Comment #14
ansorg commentedronan,
thanks for the fix. it seems to work now in 6.x-.1.x-dev
slightly off topic
I tried to do this "show parent" thing on another site where I have already 6.x-.2.x.dev but there is no "Node Hierarchy: Parent" to choose as field, the only "Nodehierarchy" field available in a view is "Node Hierarchy: Child Weight"?
Intended behavior?