Repository navigation
Is it possible to add filter options under blog posts and project section? #3795
Replies: 1 comment
|
Yes. There's no built-in filter widget, but the theme already has most of what you need. I haven't built these snippets; both follow code that's already in the repo. Blog posts. The theme already ships grouped pages: categories:
- research
tags:
- machine learningThen link to the page from For a row of links at the top of that page, add this to <p>
{% for category in group_names %}
<a href="#{{ category | slugify }}">{{ category }}</a>{% unless forloop.last %} · {% endunless %}
{% endfor %}
</p>Portfolio. Copy what portfolio_category:
software:
title: 'Software'
research:
title: 'Research'Add {% for category in site.portfolio_category %}
{% assign title_shown = false %}
{% for post in site.portfolio %}
{% if post.category != category[0] %}{% continue %}{% endif %}
{% unless title_shown %}
<h2 id="{{ category[0] }}">{{ category[1].title }}</h2><hr />
{% assign title_shown = true %}
{% endunless %}
{% include archive-single.html %}
{% endfor %}
{% endfor %}Restart This gives you sections and jump links. A filter that hides items without reloading would need a little JavaScript on top, but it's rarely worth it for a personal site. |
|
Yes. Both work without plugins, so they also build on GitHub Pages. Blog posts, one section per category: already in the template. ---
title: 'My post'
date: 2026-10-31
categories: [Research]
---Then add the page to - title: "Categories"
url: /categories/Each heading gets an id, so you can also link straight to one category, e.g. Projects (portfolio), with filter buttons at the top. Add a ---
layout: archive
title: "Portfolio"
permalink: /portfolio/
author_profile: true
---
{% include base_path %}
{% assign groups = site.portfolio | group_by: "category" | sort: "name" %}
<p class="portfolio-filter">
<button class="btn" data-filter="all">All</button>
{% for group in groups %}{% if group.name != "" %}
<button class="btn" data-filter="{{ group.name | slugify }}">{{ group.name }}</button>
{% endif %}{% endfor %}
</p>
{% for post in site.portfolio %}
<div class="portfolio-item" data-category="{{ post.category | slugify }}">
{% include archive-single.html %}
</div>
{% endfor %}
<script>
document.querySelectorAll('.portfolio-filter [data-filter]').forEach(function (button) {
button.addEventListener('click', function () {
var filter = button.dataset.filter;
document.querySelectorAll('.portfolio-item').forEach(function (item) {
item.hidden = filter !== 'all' && item.dataset.category !== filter;
});
});
});
</script>The buttons are generated from the categories you actually use, so there's nothing else to maintain. Items without a I tested both on the current |
Uh oh!
There was an error while loading. Please reload this page.
Is there any way to filter blog posts and projects, since there can be different categories?
For example, something like having a filter option at the top of the page or having separate sections for each category?
If anyone has implemented it, I would appreciate if you share it.
Thanks in advance.
All reactions