Last active
October 13, 2016 07:19
-
-
Save BryanSchuetz/443f1600d772c2e2bd9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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