I have constructed my terms like this:

  • primary term 1
    • secondary term 1
      • tertiary term 1
      • tertiary term 2
    • secondary term 2
  • primary level 2

I first thought that when I access the secondary term 1, all its nodes will show including the nodes belonging to tertiary term 1 and tertiary term 2. But it didn't turn out that way. Is there a possible way to display the term's nodes together with all of it's subterms' nodes? If none, can you suggest a workaround?

Comments

t4him’s picture

Did you check multiple select in the 'vocabulary' page.

check this option, then go back to each of your post and select 'secondary term1' hold down the 'control key' and select 'tertiar term 1' and so on. Save your post and there it is.

Hope this helps,

t4him
--*--
post back with your solution

wpd’s picture

I think the child/parent relationship in taxonomy is confusing. They does not appear to be any benefit to having child terms. The only effect is the display in the category select boxes.

You can use the views modules to do want you want. You can set it to display any of the selected terms.
http://drupal.org/project/views

here is a similiar question: http://drupal.org/node/58138
with a similiar answer ;)

White Paper Designs

dashmug’s picture

I'll just use views.module though it really didn't give me my expected results.

amanda’s picture

I know how I could hack around it by selecting multiple terms, but I want to just turn the site over to a group of users and when they go to "Secondary Term 2" I want them to see all the tertiary terms below it.

Hangya’s picture

...but you have to modify the modules/taxonomy.module file.
You should insert a new function into it, like:

function taxonomy_get_children_($tid, $vid = 0, $key = 'tid') {
  if ($vid) {
    $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_data} t INNER JOIN {term_hierarchy} h ON h.tid = t.tid WHERE t.vid = %d AND h.parent = %d ORDER BY weight, name', 't', 'tid'), $vid, $tid);
  }
  else {
    $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_data} t INNER JOIN {term_hierarchy} h ON h.tid = t.tid WHERE parent = %d ORDER BY weight, name', 't', 'tid'), $tid);
  }
  $children = array();
  while ($term = db_fetch_object($result)) {
    $children[] = $term->$key;
  }
  return $children;
}

(it's a hacked taxonomy_get_children function :) )
And change the taxonomy_select_nodes function like this:

function taxonomy_select_nodes($tids = array(), $operator = 'or', $depth = 0, $pager = TRUE, $order = 'n.sticky DESC, n.created DESC') {
  if (count($tids) > 0) {
    $children_tids = array();
    foreach ($tids as $index => $tid){
      if (taxonomy_get_children_($tid)){
        $children_tids[] = taxonomy_get_children_($tid);
      }
    }
    
    // For each term ID, generate an array of descendant term IDs to the right depth.
    $descendant_tids = array();
    if ($depth === 'all') {
      $depth = NULL;
    }
    foreach ($tids as $index => $tid) {
      $term = taxonomy_get_term($tid);
      $tree = taxonomy_get_tree($term->vid, $tid, -1, $depth);
      $descendant_tids[] = array_merge(array($tid), array_map('_taxonomy_get_tid_from_term', $tree));
    }

    if ($operator == 'or') {
      $str_tids = implode(',', call_user_func_array('array_merge', $descendant_tids + $children_tids));
      $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. $str_tids .') AND n.status = 1 ORDER BY '. $order;
      $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. $str_tids .') AND n.status = 1';
    }
    else {
      $joins = '';
      $wheres = '';
      foreach ($descendant_tids as $index => $tids) {
        $joins .= ' INNER JOIN {term_node} tn'. $index .' ON n.nid = tn'. $index .'.nid';
        $wheres .= ' AND tn'. $index .'.tid IN ('. implode(',', $tids) .')';
      }
      if ($children_tids){
        foreach ($children_tids as $index => $tids) {
          $joins .= ' INNER JOIN {term_node} tnc'. $index .' ON n.nid = tnc'. $index .'.nid';
          $wheres .= ' OR tnc'. $index .'.tid IN ('. implode(',', $tids) .')';
        }
      }
      $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n '. $joins .' WHERE n.status = 1 '. $wheres .' ORDER BY '. $order;
      $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n '. $joins .' WHERE n.status = 1 ' . $wheres;
    }
    $sql = db_rewrite_sql($sql);
    $sql_count = db_rewrite_sql($sql_count);
    if ($pager) {
      $result = pager_query($sql, variable_get('default_nodes_main', 10), 0, $sql_count);
    }
    else {
      $result = db_query_range($sql, 0, variable_get('feed_default_items', 10));
    }
  }

  return $result;
}

I haven't tested this too much, but it seems to be working.

venkat-rk’s picture

See http://drupal.org/node/41349#comment-76913 for a possible solution.

Hangya’s picture

it's a much nicer solution, thx :)

summit’s picture

Subscribing. Looking for this in relation to panels_taxonomy. Greetings, Martijn