New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: `each` function iterate through a specific category #976

Closed
ianrose opened this Issue Jan 1, 2015 · 2 comments

Comments

2 participants
@ianrose

ianrose commented Jan 1, 2015

Is there a way to have the each function iterate through a specific category name?

Take the code below and make it loop through posts that are in the articles category:

  <% page.posts.each(function(post){ %>
    <%- partial('article', {post: post, index: true}) %>
  <% }) %>

Use case would be in the index.ejs have column one displaying only the posts in the articles category, a 2nd column displaying posts in the notes category, and a 3rd column displaying posts in the projects category.

<div class="col-1">
<h1>Articles</h1>
  <% ...each(function(...){ %>
    <%- partial('article', {post: ..., index: true}) %>
  <% }) %>
</div>
<div class="col-2">
<h1>Notes</h1>
  <% ...each(function(...){ %>
    <%- partial('note', {post: ..., index: true}) %>
  <% }) %>
</div>
<div class="col-3">
<h1>Projects</h1>
  <% ...each(function(...){ %>
    <%- partial('project', {post: ..., index: true}) %>
  <% }) %>
</div>
@ianrose

This comment has been minimized.

ianrose commented Jan 2, 2015

This does the trick:

<% get_posts({
    count: 5,
    orderby: "updated",
    order: -1,
    query: {categories: 'work'}
    }).each(function(post) { %>
        <%- partial('_partial/index-post', {post: post, index: true}) %> 
<% }) %>

@ianrose ianrose closed this Jan 2, 2015

@rawaludin

This comment has been minimized.

rawaludin commented Nov 4, 2015

is it could be applied to hexo 3?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment