Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
{% comment %}
* Loop through all site tags
* For each tag, create a container with the tag title, and all posts containing that tag
* Hide the container by default and use the tag slug as an ID for the container
{% endcomment %}
{% assign sorted_tags = site.tags | sort %}
{% for tag in sorted_tags %}
<div class="tag-archive--block" id="{{ tag | first | slugify }}">
<h2>{{ tag | first }}</h2>
{% assign posts = tag | last %}
{% for post in posts %}
<p><strong><a href="{{ post.url }}">{{ post.title }}</a></strong>
{% endfor %}
</div>
{% comment %}
* Use Javascript to grab the `tag` paramater from the URL
* The tag paramater is set in the URL when a user clicks on a tag link in a post
* Then show the associated div
{% endcomment %}
{% endfor %}
<script type="text/javascript">
{% for tag in sorted_tags %}
if(location.search == "?tag={{ tag | first | slugify }}"){
$('#{{ tag | first | slugify}}').show();
}
{% endfor %}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment