Skip to content

Instantly share code, notes, and snippets.

@BryanSchuetz
Last active October 13, 2016 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BryanSchuetz/443f1600d772c2e2bd9d to your computer and use it in GitHub Desktop.
Save BryanSchuetz/443f1600d772c2e2bd9d to your computer and use it in GitHub Desktop.
{% 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