alright -- i need some help please.

i have 2 categories - tag and company. When I post on my site, and put items in both categories, they come back as one big string like this:

tag 1, tag 2, company 1, tag 3 in alpha order.

I would like it like this:
Tags: tag 1, tag 2, tag 3
Company: company 1, company 2

Is this possible?

Thanks!

Comments

mlle.yotnottin’s picture

I found this one somewhere in these forums but didn't make note of who originally posted it. Under Drupal 5 it prints out a nicely formatted taxonomy just like you requested.

If you're using phptemplate engine, this part would go into the template.php file:

/**
* Output taxonomy for node into a UL
**/
function phptemplate_print_terms($nid) {
     $vocabularies = taxonomy_get_vocabularies();
     $output = '<ul>';
     foreach($vocabularies as $vocabulary) {
       if ($vocabularies) {
         $terms = taxonomy_node_get_terms_by_vocabulary($nid, $vocabulary->vid);
         if ($terms) {
           $links = array();
           $output .= '<li>' . $vocabulary->name . ': ';
           foreach ($terms as $term) {
             $links[] = l($term->name, taxonomy_term_path($term), array('rel' => 'tag', 'title' => strip_tags($term->description)));
           }
           $output .= implode(', ', $links);
           $output .= '</li>';
         }
       }
     }
     $output .= '</ul>';
     return $output;
}

Within template files, such as node.tpl.php I then call it like this:

<?php if (count($taxonomy)): ?>
    <div class="item-taxo">
        Categories:
        <?php print phptemplate_print_terms($node->nid) ?>
    </div>
 <?php endif; ?>

I then style the "item-taxo" class in a css file.

summit’s picture

I found this snippet, duplicate of: http://drupal.org/node/106139#comment-1127485

<?php
            $vocabs = array();
            /** save $links array in other variable before the following code changes it    
            */
            $comment = $links;

            foreach( (array)$node->taxonomy as $term ) {
                $vocab = taxonomy_get_vocabulary($term->vid);
                if ( !isset($vocabs[$vocab->name]) ) {
                    $vocabs[$vocab->name] = array();
                }
                $vocabs[$vocab->name][] = l($term->name, "taxonomy/term/$term->tid");
            }

            foreach ( $vocabs as $name => $links ) {
              print '<div class="taxonomy">' . $name . ': ';
              print implode(', ', $links);
              print '</div>';
            }
        ?>