Hi All,

I like the bluemasters theme, however I find the themeing of taxonomy terms to be unclear, I created the following code to make the following change:

From:

Tags: XYZ XYZ

To:

Tags: XYZ | XYZ

Here's the code:

function bluemasters_field__taxonomy_term_reference($vars) {
  $output = '';

  // Render the label, if it's not hidden.
  if (!$vars['label_hidden']) {
    $output .= '<div class="field-label"' . $vars['title_attributes'] . '>' . $vars['label'] . ':&nbsp;</div>';
  }

  // Render the items.
  $output .= '<div class="field-items"' . $vars['content_attributes'] . '>';
  foreach ($vars['items'] as $delta => $item) {
  
    // Set a delimiter, in this case a pipe
    $delimiter = '&nbsp;|&nbsp;';
    
    // If the item is the last in the array remove the pipe
    if (end($vars['items']) === $item) {
      $delimiter = '';
    }

    $classes = 'field-item ' . ($delta % 2 ? 'odd' : 'even');
    
    // Output each taxonomy term item, with the delimiter on the end
    $output .= '<div class="' . $classes . '"' . $vars['item_attributes'][$delta] . '>' . drupal_render($item) . $delimiter . '</div>';
  }

  $output .= '</div>';
  // Render the top-level wrapper element.
  $tag = $vars['label_hidden'] ? 'div' : 'div';
  $output = "<$tag class=\"" . $vars['classes'] . '"' . $vars['attributes'] . '>' . $output . "</$tag>";

  return $output;
}

Input/Comments welcome.

To use - simply add the code before the ?> in template.php you'll need to change the "bluemasters" in the function name if you have renamed the theme or created a subtheme.

To change the delimiter simply replace &nbsp;|&nbsp; with your chosen delimiter.

E.G: For a comma use: &nbsp;,&nbsp;

Comments

Homotechsual’s picture

Title: How to add a separator between taxonomy terms » [HowTo] Add a separator between taxonomy terms
Homotechsual’s picture

Issue summary: View changes

Corrected exposed HTML code