Hi,

I'm implementing CCK taxonomy fields to add terms as tags to my content, But it displaying in following manner:

Tags: XYZ
ABC
QWR
etc

I want them to display as

Tags: XYZ , ABC, QWR etc
or
Tags: XYZ | ABC | QWR

Any help?

Comments

Rameez’s picture

Status: Fixed » Active

Why nobody replying? please reply if anyone know the answer. Thank you

Junro’s picture

Damm I want this code!

I can have XYZ, ABC, QWR, THY, ASE but if The field have only one value, I have XYZ,,,, lol

It looks like simple but when you're not an expert in php...

Junro’s picture

Status: Active » Fixed

Easy:

  $puntuacion = "";
  $i = 0;
  $max = count($field_proyectos_otrosmiembros);
  foreach ($field_proyectos_otrosmiembros as $item) {
    $puntuacion = (++$i < $max) ? ", " : $puntuacion = ". ";
    print $item['view'].''.$puntuacion.' ';
};

See http://drupal.org/node/155361

Junro’s picture

Status: Fixed » Active

Erf this is not good if we have only one value... $puntuacion is still displaying.

Junro’s picture

Status: Active » Fixed

Sorry, the code is perfect :)

Rameez’s picture

Status: Active » Fixed

HI,
Thanks a lot for help, but can you please tell me where to put this code?

I tried to replace it in content-field-tpl.php, but didn't worked for me. Please explain bit in detail?

Junro’s picture

Use the Content template module.

It's very easy to use when you have a little knowledge in php.

Rameez’s picture

Hi,

Thanks, I manage to display tags with the following code in node.tpl.php

<div class="field field-type-content-taxonomy field-field-tags">
<div class="field-label">Tags:</div>
<div class="field-items">
<?php
  $puntuacion = "";
  $i = 0;
  $max = count($node->field_tags);
  foreach ((array)$node->field_tags  as $item) {
    $puntuacion = (++$i < $max) ? ", " : $puntuacion = ".";
    print $item['view'].''.$puntuacion.'';
};
?>
</div>
</div>

But the issue is output displaying as follows:

Tags:
xyz1, xyz2, xyz3,,,,

How can i avoid 3 extra commas to get print in last? and is it possible to print "Tags:" Inline? ..Thanks

Rameez’s picture

OOps i don't know what was the reason of printing of those extra commas in the end, but its been resolve now.

Finally i ended up with following code:

<span class="field field-type-content-taxonomy field-field-tags">
<span class="field-label">Tags:</span>
<span class="field-items">
<?php
$puntuacion = "";
$i = 0;
foreach ((array)$node->field_tags as $item) {
$i = $i+1;
if ($i < count($node->field_tags)) { $puntuacion = ",  "; } else { $puntuacion = ". "; }
print $item['view'].''.$puntuacion.' ';
};
?>
</span>
</span>

Thanks for the help.

Junro’s picture

OOps i don't know what was the reason of printing of those extra commas in the end, but its been resolve now.

It's because you have to edit and save again all nodes :)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

allella’s picture

Calling count($node->field_tags) inside of the foreach loop will execute a count() each iteration. The previous examples show how you can call count() just one time before the foreach loop, which would be more efficient.

neelamssantosh’s picture

i need the input as 3

label: label: label
text-field: text-field: text-field:
can anyone help me,its urgent