2Ca0'; /* Add comma and space after each tag */ } .tags li:last-child:after { content: ' '; /* Eliminate comma after last tag */ } Here’s what those additions produce. Ta-da! A comma-separated tag list. One last note—if you want to add the number symbol (#) before each tag so that they look like hashtags (like #ui, #wireframes, #planning), just add this declaration to your CSS: .tags li:before { content: '#'; }" />

Tumblr Themes: How to Render Tags in a Comma Separated List - Midday Latte

'Tis I, House! I'm a happy designer-type.
Twitter  /  FB  /  Dribbble 

Tumblr Themes: How to Render Tags in a Comma Separated List

This is a quick tutorial on displaying tags on your Tumblr in a comma-separated list. I was prompted to share these instructions by Dorijan Covran, who wrote in to inquire about my method:

I recently started modifying a Tumblr theme and want to achieve a similar layout of tags like in your Midday Latte blog. Could you share some insights or code to achieve this?

For this example, I’m using the HTML straight out of the custom theme documentation.

{block:HasTags}
  <ul class="tags">
    {block:Tags}
    <li><a href="{TagURL}">{Tag}</a></li>
    {/block:Tags}
    </ul>
{/block:HasTags}

Without any styling, the above generates a bulleted list of the tags for that post, with each linking to a tag page. Something like this:

Hooray! Appropriately semantic. From here, I can use my stylesheet to do the rest of the work. The following CSS resets browser defaults for unordered list items, floats each one left so the list is inline, and adds commas (except for on the last item).

.tags li {
  padding: 0;
  margin: 0;
  list-style-type:none;
  display: block;
  float: left;
  }

.tags li:after { 
  content: '\002C\00a0';    /* Add comma and space after each tag */
  }  

.tags li:last-child:after {
  content: ' ';    /* Eliminate comma after last tag */
  } 

Here’s what those additions produce. Ta-da! A comma-separated tag list.

One last note—if you want to add the number symbol (#) before each tag so that they look like hashtags (like #ui, #wireframes, #planning), just add this declaration to your CSS:

.tags li:before { content: '#'; }

Notes

  1. coderipper reblogged this from middaylatte and added:
    (code & words by middaylatte.com)
  2. middaylatte posted this

Comments

blog comments powered by Disqus
Midday Latte