Although my context is in drupal, this is a general question about using optimal code for a purpose.
In drupal, in the node.tpl.php file, the default code for printing category terms is
<?php if ($taxonomy): ?>
<div class="terms"><?php print $terms ?></div>
<?php endif;?>
I came across the following code as a way to affect the url output by drupal when printing terms. The reason for wanting to do so is awkward if you don't know the quirks of drupal - please ask if curious!
I in fact only want to add "/list" to the url of all printed terms. my question is there a better way? (more efficient +/correct)
<?php
// Rather than simply print $terms, we want to control where
// the taxonomy links lead; therefore, we'll compile the list
// manually.
$term_links = array();
foreach ( $node->taxonomy as $term ) {
$term_links[] = l($term->name, "tags/$term->name/list");
}
// "implode" makes the terms comma-separated
print implode(', ', $term_links);
?>