I've created a custom foreach output that helps give me a tag id per post. I'm using commas to separate each tag. However, the last tag outputs a comma too, like this:
kittens, dogs, parrots, (<-- last comma)
How should I go about revising the foreach output so that the last comma is removed so it displays like this:
kittens, dogs, parrots
Here's the code:
<?php
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
echo '<a href="';
echo bloginfo(url);
echo '/?tag=' . $tag->slug . '" class="tag-link-' . $tag->term_id . '">' . $tag->name . '</a>, ';
}
}
?>