Home > Enterprise >  Sorting Jekyll tags by number of posts
Sorting Jekyll tags by number of posts

Time:09-22

The code which displays tags for the Jekyll theme I am using is given below. It currently shows tags in alphabetical order. What should I change to sort via post count? I saw enter image description here

CodePudding user response:

change {{ tag | first | downcase }} to {{ tag[1].size | plus: 1000 }} for sorting with post count.

The problem left is the post will appear in ascending order which can easily solved by reversing the order by adding reverse after tag are sorted.

{% capture site_tags %}
  {% for tag in site.tags %}
    {{ tag[1].size | plus: 1000 }}{{ tag | first }}
    {% unless forloop.last %}{% endunless %}
  {% endfor %}
{% endcapture %}
{% assign site_tags = site_tags | split: '' | sort | reverse %}
  • Related