At the end of every post type in my Tumblr theme, I've got this code:
<p class="permalink">
<a href="{Permalink}">{NoteCountWithLabel}</a>
{block:HasTags} # filed under:
{block:Tags}
<a href="{TagURL}">{Tag}</a>
{/block:Tags}
{/block:HasTags}
</p>
(I know the
bit is not exactly a class act. It was my four second workaround, and it's not the purpose of this question, so bear with me!)
On a post with multiple tags, that yields:
If I just add a comma after {Tag}
, making it <a href="{TagURL}">{Tag},</a>
, I get:
The last tag has an extraneous comma, and posts with only one tag would show the extra comma under this method, as well.
How do I add just the right number of commas?
Update:
Jeremy's answer below did what I wanted. But, in an attempt to get fancy be "standards-compliant" (though I don't know why anyone using IE8 would read my tumblr), I attempted to implement w3d's suggestion. So now the CSS looks like:
a.tag:before {
content:", ";
}
a.tag:first-child:before {
content:"";
}
The result is now:
(n.b.: the line break is unrelated – I added that on purpose.)
So. What went wrong?
Best Answer
I've got another idea.
This will add a span with the "tagtail" class after every tag.
Then, add this css:
This will select every tag anchor that comes after a tagtail span (so every one but the first). This way, we avoid the need to use the first-child or last-child selectors.
UPDATE:
If you want to ensure that the commas are styled apart from the anchor, I suppose you could also do:
and then style it like:
However, this might need tweaking because browsers differ on overriding rules.