[英]How to get posts by category with hexo?
与Hexo博客打交道。我有一个类别页面,其中列出了每个类别中的所有帖子。 但是我想要一个类别唯一的单独页面。 我对这里的语法不熟悉。 如何过滤称为“功能”的类别?
<div class="archives-wrap" style="margin: 0px;">
<div class="archives-category-wrap">
<blockquote>
<% if(site.categories.length) { %>
<%- list_categories(site.categories) %>
<% } %>
</blockquote>
</div>
<% site.categories.sort('name').map(function(category){ %>
<div class="archives-wrap">
<div class="archive-year-wrap" id="<%= category.name %>">
<h1 class="archive-category"><%= category.name %></h1>
</div>
<div class="archives">
<% category.posts.sort('-date').map(function(post, i){ %>
<%- partial('_partial/archive-post', {post: post, index: true}) %>
<% if (post.subtitle && post.subtitle.length) { %>
<h3 class="post-subtitle">
<%- post.subtitle %>
</h3>
<% } %>
<% }) %>
</div>
</div>
<% }) %>
我也不熟悉Hexo,但我认为一个简单的IF
语句就可以完成此工作:
<div class="archives-wrap" style="margin: 0px;">
<div class="archives-category-wrap">
<blockquote>
<% if(site.categories.length) { %>
<%- list_categories(site.categories) %>
<% } %>
</blockquote>
</div>
<% site.categories.sort('name').map(function(category){ %>
<% if(category.name == 'featured') { %>
<div class="archives-wrap">
<div class="archive-year-wrap" id="<%= category.name %>">
<h1 class="archive-category"><%= category.name %></h1>
</div>
<div class="archives">
<% category.posts.sort('-date').map(function(post, i){ %>
<%- partial('_partial/archive-post', {post: post, index: true}) %>
<% if (post.subtitle && post.subtitle.length) { %>
<h3 class="post-subtitle">
<%- post.subtitle %>
</h3>
<% } %>
<% }) %>
</div>
</div>
<% } %>
<% }) %>
一个更精细的解决方案可能是在地图之前使用过滤器功能,但是我在他们的文档中没有找到这样的功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.