Hi,

I want to set up a glossary on my Website. I know about the glossary module, but it's not updated for Drupal 5 yet and the patch submitted on the support Forum don't agree to well with my Drupal installation. I was tinking a snippet could help accomplish the result I want but I'not to wise with php and Drupal coding. Is there a good soul who could help me ? Basicly, I would like a snippet that display all the terms in one vocabulary with there description (a.k.a definition), synonyms and related terms in a list. As a alternative, I was also wondering if there is a way to use CCK to obtain the same result the glossary module would produce ? I never used CCK before but I read on the Forum that it is very powerful...

Thank for your help !

Denis

Comments

coreyp_1’s picture

CCK won't do it for you. CCK *is* powerful, but for a different purpose. CCK extends what a node can already do.

You are wanting a category listing, something that has nothing to do with nodes.

I've never used the glossary module, nor have I tested the code I'm about to give you, but it should work, just because I said so:

// $vid is the id# of the vocabulary you want shown.

$vid = 1;

print _cheap_imitation_glossary_overview($vid);

// the following code was stolen and then hacked from glossary.module

function _cheap_imitation_glossary_admin_links($vid) {
  if (user_access('administer taxonomy')) {
    $links[] = l(t('add term'), "admin/taxonomy/add/term/$vid");
    $links[] = l(t('edit glossary'), "admin/taxonomy/$vid");
    $output .= theme('links', $links);
  }
}

function _cheap_imitation_glossary_overview($vid, $letter = NULL) {
  $tree = taxonomy_get_tree($vid);
  $output = '';
  if ($tree) {
      $output .= "<dl class=\"glossary-list\">\n";
      foreach ($tree as $term) {
        if (!$letter || strtolower($term->name[0]) == substr($letter, 6)) {
          $output .= theme('cheap_imitation_glossary_overview_item', $term);
        }
      }
      $output .= "</dl>\n";
  }
  $output .= _cheap_imitation_glossary_admin_links($vid);
  return $output;
}

function theme_cheap_imitation_glossary_overview_item($term) {
  if (isset($term->firstletter)) {
    $output .= "<a id=\"letter". $term->firstletter ."\"></a>\n";
  }
  $output .= "<a id=\"term{$term->tid}\"></a>\n";
  $output .= "<dt class=\"depth$term->depth\">{$term->name}";
  if (user_access('administer taxonomy')) {
    $output .= l(t('edit term'), "admin/taxonomy/edit/term/$term->tid", array('title' => t('edit this term and definition.'), 'class' => 'glossary-edit-term'));
  }
  $output .= "</dt><dd class=\"depth$term->depth\">";
  if ($nodes = taxonomy_term_count_nodes($term->tid)) {
    $output .= l(t('Detailed definition'), "taxonomy/term/$term->tid");
  }
  else {
    $output .= $term->description;
  }
  
  if ($relations = taxonomy_get_related($term->tid, "name")) {
    $output .= "<span class=\"glossary-related\">". t("See also") . ": ";
    foreach ($relations as $related) {
      $items[] .= l($related->name, "taxonomy/term/$related->tid");
    }
    $output .= implode(', ', $items) . "</span>\n"; // strip trailing comma
    unset($items);
  }
  $output .= "</dd>\n";
  return $output;
}

Put this into a node, change $vid to the appropriate value, and enable the PHP filter.

Standard disclaimers apply: not guaranteed against hair loss or your girl/boyfriend cheating on you. Not tested on animals.

Let me know what kind of syntax errors you get from my lousy coding/hacking, and I'll try to get it straitened out for you.

- Corey

p0732658’s picture

It works like a charm! Almost perfectly. No, no hair were lost and my wife is not cheating on me ! I will play arround with this code to try adding some formating for the output (with CSS, I guest) and maybe adding a alphabetical pager. If I can't get what I want be doing it myself like a big boy, I'll get back to you on this posting.

Thank you so much !

Denis

Akela’s picture

Here is the error message I got when trying this on Drupal 6.13:

Fatal error: Unsupported operand types in \includes\common.inc on line 1552

Has anyone else gotten this (or a similar code) to work on Drupal 6.x?

coreyp_1’s picture

In D6 it is probably best to use Views, since Views 2 can now do lists of just about anything.

-Corey

p0732658’s picture

Hi again !

I also wish to add synonyms to the list. I've tried this code :

  if ($synonyms = taxonomy_get_synonyms($term->tid, "name")) {
    $output .= "<br />\n";
    $output .= "<span class=\"glossary-synonyms\">". t("See also") . ": ";
    foreach ($synonyms as $synonym) {
      $items[] .= l($synonym->name, "taxonomy/term/$synonyms->tid");
    }
    $output .= implode(', ', $items) . "</span>\n"; // strip trailing comma
    unset($items);
  }

The result is nothing ! Nothing, as it didn't produce any additional output and didn't affect the rest of the script. I not to wise with php, so I guest I probably missing something obvious for any programmers !

Thank you for your suggestion.

Denis

summit’s picture

Subscribing, greetings, Martijn