Reputation: 45
On my Jekyll page, I have three different types of postings: game, biz, thoughts, with each posting type categorized by tags.
I use the code below for my index.html as it shows the most recent postings on my site by posting time, displaying each posting in the list with 'post.title', 'post.date', 'post.tags', 'page.summary(content)' information.
However, my site has different pages for different posting category(game, biz review, and thoughts), and I would like to use this display format which I used in index.html (the code below), on the front page of each different page (game, biz review, and thoughts).
<div class="home">
<div class="post-list">
{% for post in site.posts limit:10 %}
<h2><a class="post-link" href="{{ post.url | remove: "/" }}">{{ post.title }}</a></h2>
<span class="post-meta">{{ post.date | date: "%b %-d, %Y" }} /
{% for tag in post.tags %}
<a href="{{ "tag_" | append: tag | append: ".html"}}">{{tag}}</a>{% unless forloop.last %}, {% endunless%}
{% endfor %}</span>
<p>{% if page.summary %} {{ page.summary | strip_html | strip_newlines | truncate: 160 }} {% else %} {{ post.content | truncatewords: 50 | strip_html }} {% endif %}</p>
{% endfor %}
</div>
</div>
For more clear understanding, I included some pictures that may help understanding my question.
Much thanks to the community for help in advance!
index.html showing recent postings(of all kinds) from the sites
I want the below listing to show the recent postings only from the postings with game tags.
Upvotes: 4
Views: 294
Reputation: 2871
Your loop currently iterates over the first ten posts from all tags:
{% for post in site.posts limit:10 %}
You can iterate over the first ten posts with the "game" tag by filtering for those first:
{% assign game_posts = site.posts | where_exp: "post", "post.tags contains 'game'" %}
{% for post in game_posts limit:10 %}
You'll need at least Jekyll v3.2.0 for the where_exp
filter.
Since you're planning to reuse that chunk of markup for each tag, I'd recommend looking into converting it to a layout and having the tag as a front matter variable for each page that uses it.
Upvotes: 3