I want to create a generic page to show posts belonging to two categories.
For example,
If the URL is www.blog.com/category/question/ruby
then show posts belonging to category question
and ruby
.
If the URL is www.blog.com/category/question/java
then show posts belonging to category question
and java
.
If the URL is www.blog.com/category/scala
then show posts belonging to category scala
only.
Is this possible with jekyll-archive
plugin or is there a better way?
Try tweaking this:
<h2>Question + Ruby</h1>
<ul>
{% for post in site.posts %}
{% if post.categories contains 'question' %}
{% if post.categories contains 'ruby' %}
<li><a href="{{ post.url }}">{{post.title}}</a></li>
{% endif %}
{% endif %}
{% endfor %}
</ul>
<br />
<h2>Question + Java</h1>
<ul>
{% for post in site.posts %}
{% if post.categories contains 'question' %}
{% if post.categories contains 'Java' %}
<li><a href="{{ post.url }}">{{post.title}}</a></li>
{% endif %}
{% endif %}
{% endfor %}
</ul>
This is pretty basic and could definitely be optimized, but it’s a start.
Solution above is good.
For a general approach you could go through posts and filter to were posted.categories.size > 1
Then show the categories next to the post.
If you wanted to group them under headings, I don’t know what is best to do
I get this solution but it isn’t what I asked for, unfortunately.
With jekyll-archive
plugin, you get pages automatically (with URL like www.blog.com/category/question/
and www.blog.com/category/ruby/
) that show posts of category question
and ruby
respectively.
So, is there a way to get pages automatically that will show posts belonging to 2 categories?
The solution mentioned will require me to write code for each and every category in my blog. I want this to be automated like in jekyll-archive
plugin. Hope I am making sense.
Have a look at the jekyll-paginate-v2 plugin. It’s name is a bit misleading, but in addition to pagination it can create archive pages for categories, tags, collections, etc. It provides a lot more control over how those pages are created and I believe you can achieve what you want with it…
# Jekyll::Paginate V2::Generator
The **Generator** forms the core of the pagination logic. It is responsible for reading the posts and collections in your site and split them correctly across multiple pages according to the supplied configuration. It also performs the necessary functions to link to the previous and next pages in the page-sets that it generates.
<p align="center">
<img src="https://raw.githubusercontent.com/sverrirs/jekyll-paginate-v2/master/res/generator-logo.png" height="128" />
</p>
> The code was based on the original design of [jekyll-paginate](https://github.com/jekyll/jekyll-paginate) and features were sourced from discussions such as [#27](https://github.com/jekyll/jekyll-paginate/issues/27) (thanks [Günter Kits](https://github.com/gynter)).
* [Site configuration](#site-configuration)
* [Page configuration](#page-configuration)
* [Backwards compatibility](#backwards-compatibility-with-jekyll-paginate)
* [Example Sites](https://github.com/sverrirs/jekyll-paginate-v2/tree/master/examples)
* [Paginating collections](#paginating-collections)
+ [Single collection](#paginating-a-single-collection)
+ [Multiple collection](#paginating-multiple-collections)
+ [The special 'all' collection](#the-special-all-collection)
* [How to paginate categories, tags, locales](#paginate-categories-tags-locales)
+ [Filtering categories](#filtering-categories)
+ [Filtering tags](#filtering-tags)
This file has been truncated. show original