I'm trying to output a list of the taxonomy "tags" in my drupal theme.

So far, in my node.tpl.php file I have
<?php if (render($content['field_tags'])): ?> | <span class="terms">Tagged with <?php print render($content['field_tags']); ?></span><?php endif; ?>

I want to output a list of tags separated by comments. It should look like: Tag 1, Tag2, tagfour

I'm thinking I need to create a function in my template.php file. Does anyone know what function I need to modify? I can't find it in the API.

Comments

Scott J’s picture

What about adding a field--taxonomy_term_reference.tpl.php file to your theme folder? Something like :

<div class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
  <?php if (!$label_hidden) : ?>
    <div class="field-label"<?php print $title_attributes; ?>><?php print $label ?>:&nbsp;</div>
  <?php endif; ?>
  <ul class="links inline">
    <?php foreach ($items as $delta => $item) : ?>
      <li><?php print render($item); ?></li>
    <?php endforeach; ?>
  </ul>
</div>

Then you can use styling like this in your stylesheet:

ul.links { list-style: none; margin: 0; padding: 0; }
ul.links li { display: inline; }
ul.links li:after { content: ","; } 
ul.links li:last-child:after { content: ""; }
Scott J’s picture

btw, the original template is in modules/field/theme/field.tpl.php and I found the css at http://milov.nl/2883 where there is some discussion about alternatives.

eduardo.davila’s picture

Thanks Scott, That helped me too..