I want to show posts that are from a certain category. For example, going to url http://example.com/posts/programming will list all the posts that have "programming" as their category.
My general blog index looks like below
  {% for post in site.posts %}
    <div class="post-box">
      <div class="post-title">
        <a href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
      </div>
      <span class="post-date">{{ post.date | date: "%b %-d, %Y" }}</span>
      <p class="post-excerpt">{{ post.excerpt }}</p>
      <div>
        {% for category in post.categories %}
          <a href="#">#{{ category }}</a>
        {% endfor %}
      </div>
    </div>
  {% endfor %}
If Jekyll does not automatically provide a specific url for each category, I would have to dynamically change the available posts based on the given url. I can of course create a directory dedicated to each category and then make index.html inside it, but there must be a better way.
It would be perfect if there were a way to dynamically change {% for post in site.posts %} part to {% for post in posts in some_category %} with javascript. Any help would be wonderful.
A blog category is a topic you address on your blog. Your category list is like the table of contents for your blog. Categories are broad and can encompass smaller, more defined topics (i.e., tags). A category title should be descriptive and can be several words long.
I can of course create a directory dedicated to each category and then make index.html inside it, but there must be a better way.
This is a great way to do it, isn't much work at all and works flawlessly on gh-pages. It's exactly what I do on my own sites as I prefer to keep my .md posts filed by category in the directory structure, so I simply have:
/blog/
    /_posts/20015-01-01-my-awesome-post.md
    index.html
/labs/
    /_posts/20015-01-01-my-technical-post.md
    index.html
I find it preferable for maintenance to not have 1001 posts all in _posts/ and I get the pretty permalink structure I want without entering categories in each posts front-matter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With