Code

Hexo Tag and Post List

To display all tags and each tags’ related post titles.
In EJS.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<% if (site.tags.length){ %>
<section class="archives-wrap">
<div class="archives">
<% site.tags.each(function(tag) { %>
<article class="archive-article archive-type-post">
<div class="archive-article-inner">
<header class="archive-article-header">
<h1 class="kb-header" itemprop="name">
<a class="archive-article-title" href="/tags/<%= tag.name%>"><%= tag.name%> (<%= tag.posts.length%>)</a>
</h1>
<ul class="kb-list">
<% tag.posts.each(function(post) { %>
<li class="kb-entry">
<span class="file-icon"></span>
<a class="archive-article-title" href="<%= post.slug%>"><%= post.title%></a>
</li>
<% }) %>
<ul>
</header>
</div>
</article>
<% }) %>
</div>
</section>
<% } %>
#hexo