By default, when we create a taxonomy structure like:

Vocab:
- Main Cat
- - Sub Cat
- - Sub Cat
- Main Cat
- - Sub Cat
- - Sub Cat
- Main Cat (id: 3)
- - Sub Cat
- - Sub Cat

How can we have taxonomy/term/3 list all the nodes in tid 3 as well as the nodes in the children terms?

Comments

peterx’s picture

Look for _taxonomy_term_children() and related functions in taxonomy.module. You might use code like the following code with _get_nodes_by_vocabulary_and_term($vid, $term_child) being a recursive function you create.

			$taxonomy = $page_node->taxonomy;
			$term_object = reset($taxonomy);
			$vid = $term_object->vid;
			$tid = $term_object->tid;
			$term_children = _taxonomy_term_children($tid);
			if(is_array($term_children))
				{
				foreach($term_children as $term_child)
					{
					$child_nodes = _get_nodes_by_vocabulary_and_term($vid, $term_child);
					foreach($child_nodes as $child_node_id)
						{
						$child_node = node_load($child_node_id);
						if($child_node->nid == $child_node_id)
							{
							print node_view($child_node, true);
							}
						}
					}
				}

petermoulding.com/web_architect

dericknwq’s picture

Is your code meant to be plugged into the template files? There are quite alot of things I wish to do and am resorting to just coding directly in the template files. I'm not too sure if that should be the way though. :(

And by default taxonomy/term/x will already query for the nodes. How can I stop it from doing so? Otherwise, I will be querying twice right?

elhombresinatributos’s picture

Dirty but effective.

Open modules/taxonomy.module in a text editor (back it up at first!!)
Find the line:

$tree = taxonomy_get_tree($term ->vid, $tid, -1, $depth);

and repace the last $depth with NULL

$tree = taxonomy_get_tree($term->vid, $tid, -1, NULL);

It's working in Tabernil.com.

Regards.

PS: This answer was found somewhere in drupal.org, I don't remember where.

dericknwq’s picture

Thanks for that, I'm really trying to refrain from touching any of the core modules. In fact I had the idea that Drupal was set up in a way that they has to be things that can be "hooked" on instead.

peterx’s picture

I used the code in page.tpl.php. If you put code into a function then call the function, put the function in template.php as template.php is called before all the other parts of your template.

There are several related functions in taxonomy that can be used by templates. Read through them to see what data they return. Some return raw data and some return formatted HTML. The functions can also be used in blocks and content when you want very specific detail.

petermoulding.com/web_architect

aymerick’s picture

Simply add the 'all' parameter to your URL.

So in your example, go to: taxonomy/term/3/all

aymerick’s picture

I have created a new module to enable this behaviour: http://drupal.org/project/taxonomy_forceall