I've added some freetagging taxonomies to a content type. Now I would like to create a View and display all tags as a comma-separated list, e.g.:
Music: Lady Gaga, Michael Jackson, The Beatles
Movies: Avatar, Titanic
I added the taxonomy fields to my View, but they only display the very first value/tag/term (e.g. here: Lady Gaga and Avatar). When I mark the "group similar fields" option, all values/tags are displayed, but not as a comma-separated list, but as follows:
<div class="field-item field-item-0">Lady Gaga</div>
<div class="field-item field-item-1">Michael Jackson</div>
<div class="field-item field-item-2">The Beatles</div>
i.e. listed below each other. Of course, I can user float:left; padding-right:10px; in the divs to display them inline, but it is too hacky and the commas are missing anyways.
Comments
Comment #1
huntsinger commentedComment #2
merlinofchaos commentedIs this a CCK field? The field-item tag suggests it is. There should be a 'group multiple values' checkbox that will do that. In any case, it's a CCK request.
Comment #3
jaochoo commentedYes, it is a CCK field (taxonomy field) but my question is about how to display this field in a View. I know how to add it to a a View, but:
a) For the 'group multiple values' checkbox I will get an output like mentioned above, i.e. every tag/term produces an own
<div>element, i.e. having all tags/terms listed in separate rows rather than getting a comma-separated list of terms;b) Not checking the 'group multiple values' checkbox I will only get the very first term/tag.
So both are not satisfying.
Comment #4
merlinofchaos commentedPlease read the submission guidelines for an explanation of why I say this is a CCK request.
Comment #5
trevorjfitz commentedSo my friends, any resolution on this? It seems like a views request. Honestly, I don't really care what kind of request it is, I'm just curious how to solve the problem. Huntsinger, where would you suggest putting that code - seeing as we are trying to implement this solution in a view.
Thanks Drupal studs.
Comment #6
jaochoo commentedSo as requested I moved this into the CCK queue. I am still interested in a solution. AFAIK same happens with the userreferences. Can someone explain how to display such multiple data (taxonomy terms, user references, node references, etc.) as a comma-separated list, just like OG produces a comma-separated list of groups?
Comment #7
karens commentedCCK does not handle that field, I'm guessing you're using Content Taxonomy.
Comment #8
mastoll commentedI am not using Content Taxonomy and I have the same question.
Via a view, I'm displaying all of the taxonomy terms assigned to a particular node. Those terms are grouped by vocabulary. They are displayed each in their own div tag, therefore visibly in a list.
How to display them inline, with a coma between each term?
Comment #9
xjmFor Content Taxonomy, see: #749432: comma separated, ordered list and unordered list.
You can also accomplish this in the theming layer, using either a theme override or CSS.
For a possible contrib module solution, see also: http://drupal.org/project/custom_formatters
Comment #10
azabeti commentedOne solution would be to use hook_preprocess_node function in template.php
Then in node.tpl.php use:
print $variables['taxonomy']['term_links']There's probable a way to inset into the node object, but I haven't figured that out yet.
Comment #11
lahode commentedIf it helps someone, here is an export of my formatter with custom_formatter. You can just import it and use it:
$formatter = new stdClass();
$formatter->disabled = FALSE; /* Edit this to true to make a default formatter disabled initially */
$formatter->api_version = 2;
$formatter->name = 'terms_with_comma';
$formatter->label = 'Terms with comma';
$formatter->description = '';
$formatter->mode = 'php';
$formatter->field_types = 'taxonomy_term_reference';
$formatter->code = '$termLinks = array();
if (isset($variables[\'#items\']) && is_array($variables[\'#items\'])) {
foreach ($variables[\'#items\'] as $item) {
$term = taxonomy_term_load($item[\'tid\']);
if ($term) $termLinks[$term->tid] = l($term->name, \'taxonomy/term/\' . $term->tid);
}
}
return implode(\', \', $termLinks);';
$formatter->fapi = '';
Cheers
Comment #12
jwilson3This can also be done with a module: https://drupal.org/project/textformatter
Comment #13
jospratiklive commentedI did tried the 'textformatter' module, it does not work for 'Content Taxonomy Fields' type cck field.
Comment #14
pringlz commentedsolve my case
https://www.drupal.org/project/taxonomy_formatter