Hi there,

Here is my case. I have two node types: A and B. A has some text fields and B i as picture (CCK imagefield). The hierarchy is simple: One A has many Bs (pictures).
A
|- B1
|- B2
|- B2
|- B...

The B-nodes have to be shown as image thumbnails.

I would like to be able to display a few of the child-pictures of A in the full node display of A and have a "more"-link that will lead to a gallery-style page with all of the child pictures.

I used imagecache module to create a view that displays a thumbnails page with the children of a given A-node. I also added the "actions" field to it. It has a page URL of the type: http://mysite/views/show_pics/19
In this case 19 is the nid of the parent A-node.

This works fine however I cannot configure a block-view to work. My idea was to have a block-view that shows a few children only and that has a more-link. The more-link will automatically lead to the page-view. This unfortunately does not work or I don't know how to do it.

A good idea also would be to be able to replace the rendering of the "children" tab with a view. The way it currently works it shows a plain list. What I would like to display instead (again) is a thumbnails page with the child pictures.

Can you please help me with some ideas of how to configure the described behavior?

Thanks a lot!

Comments

leanazulyoro’s picture

Have you considered the use of nodeimages module? it pretty much covers every featured you described

kirilius’s picture

I tried that in the past and decided not to use it for a number of reasons. I like the idea of having separate image NODES instead of just images. Also the views provide a very powerful way of grouping and displaying arbitrary nodes together. For example: "show all images that are posted by user X" - regardless of the parent node. If I wanted to do this with nodeimages, I'd have write custom code. With the views integration on the other hand, this is a like breeze.

I really like the idea of node hierarchy module. I only need some more ideas around the views integration.

mr_dimsum’s picture

I'm looking for something similar. Is there a method to display the fields of the child node on the parent node page? My child nodes also, each represent an image. I want to display the text field, as well as an image thumbnail created from ImageField/ImageCache on the parent page.

Cheers,
D.

ronan’s picture

Is there a method to display the fields of the child node on the parent node page?

Yup. Enable nodehierarchy_views and the views module. Create a view of type list with the fields you want to display (as well as any filters you want, you can leave the arguments empty). Chose your view from the "Embed Children View" pulldown on the parent node.

Hope this helps

mr_dimsum’s picture

Thanks for the very quick reply.

In regards to this method, you are implying that I would be able to extract any field (including CCK image fields of the child) and display it on the parent?

mr_dimsum’s picture

UPDATE: Wow.. It works! Ronan, thanks for the amazing module. I've been going on boards and people are spinning in circles on how to achieve this with Node Relativity. I'll definitely have to mingle with this a bit more to figure it out.

Is there a method to set a node type to auto-attach a view rather than doing it manually, as I'd like to automate the process so members don't have access to the controls.

Furthermore, it seems there is no filtering based on parent node for Views as Node Relativity provides. This poses a problem for dynamically generated child node fields appearing in parent nodes. I have two separate nodes and have set them both on a view that contains child node fields for display. Problem is, both nodes show the image from the child node, even though it only belongs to one parent.

ronan’s picture

Is there a method to set a node type to auto-attach a view rather than doing it manually, as I'd like to automate the process so members don't have access to the controls.

That is not currently available, but it's on my feature list for version 2 as soon as I get around to working on that. What I do for this setup is to add the logic for that into the template file for the given node type, but if you're not comfortable with php, this may not be an option for you.

Furthermore, it seems there is no filtering based on parent ID for Views, as Node Relativity provides, which poses a problem for dynamically generated child node fields appearing in parent nodes. I have two separate nodes and have set them both on a view that contains child node fields for display. Problem is, both nodes show the image from the child node, even though it only belongs to one parent.

I'm afraid I don't totally understand what you're trying to achieve here.

mr_dimsum’s picture

What I mean by the second query is that.. Node Relativity provides filtering for views, so I can create a view based on the parent-child node relationship. If I would integrate this view into my parent node page, than it would display the child node information on the node page. Node relatively, already does this, so there is not much point to it.

But.. With Node Hierarchy, there is no filter provided that would allow me to filter based on the relationship.

My Drupal test site currently has 2 nodes: Primary node is called "Game". The child-node is called "Game Cover". When I apply the settings you instructed me to do above in Post #4, everything works dandy, except there is no parent-child filtering, so every primary "Game" node I have potentially displays a child that is unaffiliated with it.

Hope that clears it up. And if in fact, there is already some type of filtering, consider me flat-out lost. :D

Thanks for the amazing rapid replies.

UPDATE: I think this is issue is resolved with the Argument provided with Node Hierarchy called "Node Hierarchy: Parent Node ID"!

ronan’s picture

UPDATE: I think this is issue is resolved with the Argument provided with Node Hierarchy called "Node Hierarchy: Parent Node ID"!

I think that is in fact what you're looking for. The nh view embed code should be adding that argument automatically, but it occurs to me that there might be a bug in that code that is causing the situation you had initially. I'll check into this possibility and get that fixed if that is the case.

Meanwhile the fix (as I think you've discovered) is to add the "Parent Node ID" argument to the view you are using yourself. (That or start by cloning the nodehierarchy_children_list view which has that argument added to it.)

CoolDreamZ’s picture

Excellent! I too have been struggling with this and seem to have very similar requirements to mr_dimsum. I also have the requirement to

...auto-attach a view rather than doing it manually, as I'd like to automate the process so members don't have access to the controls

I look forward to Version 2!

I have been experimenting with one other option, using the ViewField CCK module you can also embed a view in a node, see here http://drupal.org/project/viewfield

Thank-you very much for these tips

CoolDreamZ’s picture

An update to my experiments with ViewField.

I can (almost) achieve the desired effect using a ViewField with the associated View configured as above for the node children with the additional argument %nid in the ViewField configuration. This required the application of a patch to the latest dev version of ViewField to prevent view options appearing on the Node Edit page (see below). I say almost, because I have these residual issues:

1. The ViewField appears in both Teaser and Node Pages (I just want it on the Node Pages) - ViewField issue
2. I would now like to hide the "Node Hierarchy" view selection option on the Node Edit page, any ideas here?

The patch for ViewField: #217757: "Force default" doesn't hold true to arguments

The ViewField Teaser Issue: #239309: How to control view visibility in teaser

ronan’s picture

Good idea in viewfield. Thanks for the tip.

2. I would now like to hide the "Node Hierarchy" view selection option on the Node Edit page, any ideas here?

For users other than user 1 you can remove the 'edit embedded child view' permission and this selector will go away. Unfortunately user 1 always has all permissions, so that user will always see it.

Thanks again

CoolDreamZ’s picture

That did the trick, thanks for your advice.

Unfortunately user 1 always has all permissions, so that user will always see it

I am User 1 so it is not a problem for me :-)

ccshannon’s picture

First, thank you thank you thank you for this most useful module.

My question is along the lines of what mr_dimsum inquired about, where you said:

What I do for this setup is to add the logic for that into the template file for the given node type, but if you're not comfortable with php, this may not be an option for you.

I'm comfortable with it. Any samples? :-D

I've created an album View with the URL "galleries/$arg" which accepts the parent-node ID and creates a view of child nodes in a grid for just that parent.

I want an automatic link to the view (galleries/[nid]) in the parent-nodes , something like

"<a href='/galleries/" . $node->nid . "'>See the pictures!</a>"

Tried using Contemplate for the link and it sorta worked, but made a mess of layout.

Also, if I want to pull parent-node title and description and display into the headers of child-nodes or views, what is the syntax for the objects in nodehierarchy? $node->$parent_id[title]??? Sorry if this is a silly question, I'm not yet sure how to locate the object names in Drupal.

Any suggestions are welcome, and thanks again for this module!

ronan’s picture

I want an automatic link to the view (galleries/[nid]) in the parent-nodes , something like

"<a href='/galleries/" . $node->nid . "'>See the pictures!</a>"

Tried using Contemplate for the link and it sorta worked, but made a mess of layout.

You can just drop the code in your node.tpl.php or node-NODETYPE.tpl.php file but ad it as:

<a href="/galleries/<?php $nid ?>">See the pictures!</a>
Also, if I want to pull parent-node title and description and display into the headers of child-nodes or views, what is the syntax for the objects in nodehierarchy

For efficiency reasons, nodehierarchy does not load a node's parent object unless it needs to, so to display any info from the parent object you will need to load it first with:

$parent = node_load( $node->parent );

and then you can aces the title etc using:

echo $parent->title;

Good luck
R

mr_dimsum’s picture

Thanks for all the comments everyone! I have multiple child nodes for a parent and allow my visitors to upload as many child nodes as they want. For the parent node though, I'd like it to grab the first uploaded child node image and display it on the node page, as well as possibly on the teaser. Of course, being that I only want one image, I'd need to limit this to only the first image the applies.

Basically, I have game covers being uploaded and a master profile (parent node) of a game with all the attached images underneath it for download. I use ImageField with ImageCache and have a preset that Crops and Scales it so it crops out the front cover rather than the entire front, binding, and back of a game or DVD sleeve. This essentially, is the thumbnail I'd want extracted and displayed on the parent node teaser/node page.

Any ideas? If anybody has any slightest clue as to how to do this, I'll be willing to donate a small sum to Ronan for his services for this really great module, as 2.0 will seem to serve our desires more proficiently.

If anybody can elaborate a bit more on what csshannon did with the Node View accepting an $arg as well, that'd be great. I'm perplexed by the intricacies of Drupal, but appreciate the help from the great community.

CoolDreamZ’s picture

Try this:

  1. Create a View as described elsewhere in this post that selects the children of the Parent Node
  2. Configure this view to return a page with the maximum number of nodes=1
  3. Configure the Sort Criteria for the view using Node: Created Time as you wish.
  4. This view will now return the latest (or oldest) Child Node according to the criteria you specified
  5. Add a ViewField to the Parent Node and configure it to use the child view you created at Steps 1-3
  6. Configure the visibility (Teaser and/or Full Page) of the ViewField on the Display Fields tab of the Parent Node content type edit page

That should do it! If you want different child views on Teaser and Full Pages then repeat the above to create a second view and configure the visibility accordingly. If you only need one view then this may also work with the Embedded Child View functionality of Node Hierarchy but I haven't tested this.

Whilst experimenting with this I also discovered another cool thing about Node Hierarchy, a custom sort criteria is available for a View that allows you to sort the contents of a child view according to the order of the children specified by the user when editing the Parent. Excellent!!

mr_dimsum’s picture

Thanks for the interesting idea.. I'll have to give this a run tonight!

ccshannon’s picture

Thanks for that. Yes, this helped immensely. I also found the information I need regarding pulling parent node information into a view.

Hey, mr_dimsum, sorry I was away from my computer a couple days. Here is what you do to create an automatic view for any parent.

I found this tutorial for creating automatic per-Image Gallery thumbnail pages using Views and Taxonomy terms, based on the Image module (Image Gallery, Image Import, etc). Read this information, then make the following changes when creating the View per-PRENT NODE as opposed to per-TAXONOMY TERM.

http://drupalworx.com/node/80

... ok:

You have two Content Types for what you're doing:
- Parent Type (your Profile master node)
- Child Type (your Image/Imagefield node)

I suggest creating 2 Views, first the parent node type view, your index of published parent nodes:

- First, create the View of published profile (parent) types

- Make a Page view, as many nodes as you want.

- Give it a URL of something like "profiles" so that you will have mysite.com/profiles for your view.

- Make it a teaser list (if you want to control the fields better, try List or Table Views)

- Filters. Select Node:Type->Is One Of-> (or whatever your parent node type is called). Select another filter of Published=Yes.

- Save your view

For the Thumbnail view of Child Nodes per Parent:

- Create the View and give it the URL "profiles/nid/$arg" or you could just make it "profiles/$arg" but I'm cloning the Term ID instructions and these are Node IDs we'll be using, so I'm going with the "nid/" argument to be anal retentive.

- make it a Page View, and if you have Bonus Views installed, use "Bonus: Grid View". Give it a Pager if you expect to have more Child Nodes than the Max. number per View page.

- Again, do everything as described in the above link, but under Arguments, instead of using Taxonomy Term ID, you select Node Hierarchy: Parent Node ID as the Argument. Now, here is where I'm a little green. I put %1 (which is the Node ID from the parent) into all three boxes: Title , Wildcard, and Wildcard Sub, but I think I don't need it for Sub necessarily (will play with that).

- Under Filters, select Node:Type, make sure it is the Node Type of your CHILD type (image, etc) and Published=Yes (there's more that can be done to control the filtering, here, but this is all you need to show published children of your parent node.

- Save the View.

Now, create a new parent node (your "profile" node) and some children for it. Publish your nodes.

- Go to yoursite.com/profiles to see the list of published profile nodes. Click into your profile node. Notice its URL and the number for that Node. There is the Node ID.
- Copy the Node ID.
- Go to yoursite.com/nid/profiles/ where node_id is that same parent node number.
- So, now, anytime you publish a parent node type and its children, there is automatically a grid view for the children using the new view URL, which accepts a Node ID as its argument.

My challenge wa how to have a link to that Grid View show up in my Parent Nodes, using the template. Ronan's use of "load_node($node->parent)" showed me how to make a custom template for my child node type, where I can pull information about the parent node, into all child nodes.

And, to do the same with Views, I just edited the Header for my Grid View, choose Input Formats -> PHP and then use something like this:

<?php
$nid = arg(1);
$node = node_load($nid);
print $node->body;
?>

And the description text for my parent node now appears in the header of all the Grid View pages for that parent node.

I'm trying to create multiple options for an editor/user to create image galleries base on Use Cases:

Frontpage Teaser -> Parent Node -> Grid View -> Child Node
Frontpage Teaser -> Grid View -> Child Node
Frontpage Teaser -> Teaser of Parent Node links to First Child Node

So I want to create 3 simple teaser views based on whether the parent node is published, but where one view takes the anonymous to the parent node itself, direct to a grid view, or direct to the first child node (where the user cannot see the parent node - it is only for editors to store master data for the overall child set.)

I'm kind of a blatherer, so I hope this was not too wordy and was helpful for people. Thanks, folks!

johndobbins’s picture

this works beautifully with what i'm doing...
i have a big problem though.

how do i adjust the weight of children's view (block)

please help me

in desperate need

thanks

another workaround might be to assign it to a lower region (can't figure out how to do that either)

thanks again

dgorton’s picture

The order of children is exposed to views -- so if you're creating a view, choose to sort by "Node Hierarchy: Sort Order" in your View's "Sort Criteria". Is that what you're after?

ronan’s picture

johndobbins:

Do you mean you want to adjust where the embedded children appear on the parent node's page? There is currently no way to adjust this with the ui. A workaround might be to edit your node.tpl.php template to place the embedded children yourself. The line you will need to add is something like this

<?php echo $node->content['nodehierarchy_children']['#value']; ?>>

ablewave’s picture

I think this approach might be a good fit for me, but my child nodes are type=Image and I don't see an option for fields of thumbnail or anything like that in Views. Also tried editing the teaser and body templates, and including those fields but the images still won't appear. Any advice?

To clarify, using Imagecache and not seeing the Imagecache fields.

ablewave’s picture

Got it, sorry I didn't realize I had to use CCK imagefield/filefield to make this happen. I was really hoping to use standard image nodes, but I guess I will have to reconstruct this from scratch.

jponch’s picture

Version: 5.x-1.x-dev » 6.x-1.2

Here's my scenario - can't quite seem to figure out of any of these really speak to it. I'm using drupal 6, so d5 modules aren't an option here. I have a site full of magazines. So there are two content types for magazines which are:

Publication (parent node)
Issue (child node)

The Publication node type has a taxonomy vocabulary applied to it for categorization

The Issue node type has an image field for cover image

I want to create a taxonomy term view that displays all publications (since that's what he taxonomy term is applied to) for that term, but I want it to show the latest cover image from the publication's child nodes in the view with each publication. Any idea as to the best way to do this?

zeezhao’s picture

subscribing.

Ok. I figured out that you can change nodehierarchy_children_list view via views. If I want to make additional views available to nodehierarchy, please what is the best way without hacking the code? Thanks

jbylsma’s picture

Component: Miscellaneous » Drupal/PHP Code
Status: Active » Fixed

Cleaning the queue.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.