I would like to use the terms that are printed at the bottom of my nodes to construct a link in a block. The terms that are displayed are exactly what I have to insert into a url to call a view. And these Url's I would like to show in a block.

My question now is:

Where do these terms come from ( which function?)?
Can I reuse them somehow?

How can I get them printed ( displayed ) in a block?

I think if I can display them in a block, it should be easy to construct a url.

Any ideas?

Comments

clown10’s picture

Does nobody has an idea?

joachim’s picture

Try searching for 'taxonomy block'.
There may well be a module that does this.

clown10’s picture

Thanks for the answer, but unfortunately this not available for D6.

I found this code:

if (arg(0) == 'node' && is_numeric(arg(1)) && is_null(arg(2))) {
   $nid = (int)arg(1);
   $vocabularies = taxonomy_get_vocabularies();
   foreach($vocabularies as $vocabulary) {
     if ($vocabularies) {
         $terms = taxonomy_node_get_terms_by_vocabulary($nid, $vocabulary->vid);
         if ($terms) {        
           print '<div class="terms">' . $vocabulary->name;
           $items = array();
           foreach($terms as $term){
             $items[] = l($term->name, 'taxonomy/term/'.$term->tid);
           }
           print theme('item_list', $items);
         }
     }
   }
}

But it seems to work only with D5. Does anybody know what I have to change here?

alan d.’s picture

This fragment may be what your looking for:

<?php

if (module_exists('taxonomy')) {
  if (arg(0) == 'node' && is_numeric(arg(1)) && is_null(arg(2))) {
    if ($node = node_load(array('nid' => arg(1)))) {
      $terms = taxonomy_link('taxonomy terms', $node);
      return theme('links', $terms);
    }
  }
}
return '';

?>

Alan Davison
www.caignwebs.com.au

Alan Davison
clown10’s picture

YES! YES! YES!
Thank you very much!

clown10’s picture

If it would be possible to sort the terms by vocabulary now, I would have everything I want. Any ideas?

alan d.’s picture

An array sort would be what you want: http://au.php.net/manual/en/function.uasort.php

eg: something like,

<?php
// in the same file as the block code
function my_links_sort($a, $b) {
  return (strcmp ($a['title'],$b['title']));
}

// and modify the links block to
if (module_exists('taxonomy')) {
  if (arg(0) == 'node' && is_numeric(arg(1)) && is_null(arg(2))) {
    if ($node = node_load(array('nid' => arg(1)))) {
      $terms = taxonomy_link('taxonomy terms', $node);
      my_links_sort($terms, 'my_links_sort');
      return theme('links', $terms);
    }
  }
}
return '';
?>

It may require a bit of debugging, but should sort based on the title attribute.

Enjoy :)


Alan Davison
www.caignwebs.com.au

Alan Davison
clown10’s picture

Cool,

thank you so much!