Block with child terms of a term - how to

konrad1811 - October 26, 2009 - 20:05
Project:Taxonomy Filter
Version:6.x-1.0
Component:Documentation
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

Hi. I read docs but it's not very long. I'd like to ask if You cloud advise me.
I need to display some kind of menu with child terms.
I have panel pages with an arguments. Each page have argument - a term which contains some child terms.
And I'd like to display a block with only thos child terms depanding on page.
Is this possible to do this with Taxonomy Filter module?
I described my request more here:
http://drupal.org/node/607116

#1

solotandem - October 26, 2009 - 20:25

Draw me a picture (in words if need be, unless you have a site in progress that shows this). I just want to be sure I understand your request.

Are you using panels? What other modules?

#2

konrad1811 - October 26, 2009 - 22:21

I have panels and views.
Having a term(argument) I want to display its child-terms.
I tried to send argument (term that has child-terms) from panel to view and prepare view so that it could display children taxonomy terms, but Views don't allow that to show children terms...
Hope I'm clear.

#3

konrad1811 - November 17, 2009 - 08:21
Title:Block with child terms of a term» Block with child terms of a term - how to

Still nothing...
I belive there is an inteligent way to do this (like views/panels and arguments) by not just typing the links...
However If someone know "how to..." please to show this step by step...

#4

chawl - November 26, 2009 - 22:53

This is a hand-made function that I put in my template.php (nothing to do with TF or any other module). This gets all the terms of the node and lists their children in a block if there are any. Parent terms are turned into h2 titles and children are listed under.

<?php
function child_tree_build() {

  if (
arg(0) == 'node' && is_numeric(arg(1))) {
 
   
$node = node_load(arg(1));
 
    if (
count($node->taxonomy)) {

      foreach (
$node->taxonomy as $term) {

       
$tchild = taxonomy_get_children($term->tid, 2, $key = 'tid');
   
        if(
count($tchild)>3) {
         
$items = array();
         
$subtree = taxonomy_get_tree(2, $term->tid, -1, 1);

          foreach(
$subtree as $children) {
           
$items[] = l($children->name, "taxonomy/term/$children->tid");
          }

          print
"<h2><span>". l($term->name, "taxonomy/term/$term->tid"). "</span></h2>";
          print
theme('item_list', $items);
        }
      }
    }
  }
}
?>

Then I added a new block which contains:

<?php
print child_tree_build();
?>

You should use PHP-code input type for the block of course. This code does not check if terms are associated with a node or not, so empty terms are also listed.

I hope this might be inspiring.

#5

konrad1811 - November 27, 2009 - 06:26

Great! Thanks! - I'll check this out!

 
 

Drupal is a registered trademark of Dries Buytaert.