In node.tpl.php, the following code shows links to all categories to a node, regardless of what kind of categories they are. print terms;

If all you want are to list the tags, use the following PHP snippet in place of the code that displays categories. You will need to know which vocabulary you've set as "free tagging", that is, which vocabulary ID. Change the first line to reflect your settings. If you don't yet have a vocabulary set to free-tagging, click administer » categories » add vocabulary tab and check the box next to "Free tagging" after you've filled in the other required fields.

Note: for 4.6 sites, you will need to apply the free-tagging backport patch to your code. The patch requires a fairly advanced knowledge of modifying your Drupal install, so back up everything before attempting the patch. For sites based on the 4.7 Drupal code, this snippet works without any modification necessary to the software..

So replace the code in node.tpl.php above with the code below, and it will show a comma-separated list of tags linked to their individual taxonomy term pages.

  $vid = 1;
  $result = db_query("SELECT t.tid, t.name FROM {term_data} t, {term_node} r WHERE r.tid = t.tid AND r.nid = %d AND t.vid = %d ORDER BY weight, name", array($node->nid, $vid));
  while ($term = db_fetch_object($result)) {
    $tags[] = l($term->name, 'taxonomy/term/' . $term->tid);
  }
  if ($tags) {
    print t("Tags: ") . implode(', ', $tags);
  }

Comments

Shane Birley’s picture

Under Drupal 4.7, there is an error in the code and displays the term "array" in front of all other tags.

<?php
  $vid = 6;
  $result = db_query("SELECT t.tid, t.name FROM {term_data} t, {term_node} r WHERE r.tid = t.tid AND r.nid = %d AND t.vid = %d ORDER BY weight, name", array($node->nid, $vid));
  while ($term = db_fetch_object($result)) {
    $ntags[] = l($term->name, 'taxonomy/term/' . $term->tid);
  }
  if ($ntags) {
    print t("tags: ") . implode(', ', $ntags);
  }
?>

---
Shane Birley
Left Right Minds
https://www.leftrightminds.com

greg.harvey’s picture

To achieve a similar thing in Drupal 5.x and respect the layers of Drupal, you can do something like this in hook_nodeapi() :

/**
 * Implementation of hook_nodeapi().
 *
 * Appends book navigation to all nodes in the book.
 */

function yourmodule_nodeapi(&$node, $op, $teaser, $page) {
  switch ($op){
        case 'view':
          // code for isolating free tags
          $result = db_query("SELECT vid FROM {vocabulary} WHERE tags = 1");
          while ($vocab = db_fetch_object($result)) {
            $vid = $vocab->vid;
            $result = db_query("SELECT t.tid, t.name FROM {term_data} t, {term_node} r WHERE r.tid = t.tid AND r.nid = %d AND t.vid = %d ORDER BY weight, name", array($node->nid, $vid));
            while ($term = db_fetch_object($result)) {
              $tags[$vid][$term->name]['title'] = $term->name;
              $tags[$vid][$term->name]['attributes']['title'] = $term->name;
              $tags[$vid][$term->name]['href'] = 'taxonomy/term/' . $term->tid;
            }
            if ($tags) {
              $node->tags = $tags;
            }
          }
        break;
  }

This puts the result of any free tag vocabulary in a separate array called "tags", with a nested array for each vocabulary - thus allowing you to get a handle on a specific vocab from the node object by fetching $node->tags->$vid.

From there you can pass your tags to your theme in template.php, for example, to simply render all free tags attached to a piece of content in a standardised way, you might do something like this:

/**
 * Prepare the values passed to the theme_node function to be passed
 * into a pluggable template engine.
 */
function whattalent_node($node, $teaser = 0, $page = 0) {
  if ($node->tags) {
    foreach ($node->tags as $vocab) {
      foreach ($vocab as $term) {
        $tags[] = $term; 
      }
    } 
  }
  $variables = array(
    'tags'           => theme('links', $tags),
  );

  return _phptemplate_callback('node', $variables, array('node-' . $node->type));
}

Now you have a $tags variable available in your PHPTemplate .tpl.php files which contains all the terms, as links, from your free tagging vocabs. And, best of all, you're respecting the layers of Drupal so theming becomes easier and if you switch theme, you don't lose your functionality. =)

--
http://www.drupaler.co.uk/