Skip to content

Instantly share code, notes, and snippets.

@zeroeth
Created May 11, 2013 05:06
Show Gist options
  • Select an option

  • Save zeroeth/5558969 to your computer and use it in GitHub Desktop.

Select an option

Save zeroeth/5558969 to your computer and use it in GitHub Desktop.
Attach post labels to blog post as classes, see it in use at http://moctopsgolbblogspotcom.blogspot.com/ view source and search for "dogs_post"
<!-- this goes in the <head> -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
// For every post
$('.post-outer').each(function() {
// Find all its labels
var label_links = $(this).find('.post-labels a');
// Extract the text from them and append _post
var label_names = label_links.map(function() { return $(this).text()+"_post"; }).get();
// Add these to the post as css classes
$(this).addClass(label_names.join(" "));
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment