I'm working on setting up a used bookshop using Drupal ecommerce and multiple taxonomies. In the product display, which is using the node.tpl.php code, I post a book with various settings and the taxonomy list appears as one long string on one line, for example:

Smith, Kristine Harper EOS Book In Stock Science Fiction Gently Used

What I want to display would be the terms on multiple lines with labels:

Author: Smith, Kristine
Publisher: Harper EOS
Item Type: Book
Status: In Stock
Genre: Science Fiction
Condition: Gently Used

Since the node.tpl.php just does a print $terms it doesn't look like I have much in the way of formatting options. What can I do to get this how I want it?

Comments

nevets’s picture

Replace the code you have above with

<?php
foreach( $node->taxonomy as $term ) {
  $vocab = taxonomy_get_vocabulary($term->vid);
  print '<div>' . $vocab->name . ': ';
  print l($term->name, "taxonomy/term/$term->tid");
  print '</div>';
}
?>
Xangis’s picture

Well, each line has its own vocabulary.

The code you provided works PERFECTLY. Thank you SO much!

bgogoi’s picture

When the author vocabulary field is set to Free Tagging, and when there are multiple authors, the above code displays like

Author: John
Author: Harry

But how to display them together as :

Author: John, Harry

??

nevets’s picture

How about something like this

<?php
$by_vocab = array();

foreach( $node->taxonomy as $term ) {
  if ( empty($vocab[$term->tid]) ) {
    $vocab = taxonomy_get_vocabulary($term->vid);
    $vocab[$term->tid]['name'] = $vocab->name;
    $vocab[$term->tid]['links'] = array();
  }
  $vocab[$term->tid]['links'][] = print l($term->name, "taxonomy/term/$term->tid");
}

foreach( $by_vocab as $set ) {
  print '<div>' . $set['name'] . ': ';
  print implode(', ', $set['links']);
  print '</div>';
}
?>
summit’s picture

Hi,
Great snippet, could you tell me please how I can get to every specific term in the vocab, and use it independent of the others?
Greetings,
Martijn