Hello! I’ve been following the video to filter posts by tags:
It’s pretty useful, and I have it working. However, the experience that I got working could be improved. There are a couple of things I didn’t manage to make work:
1) How the link to category doesn’t go back to the top of the page? Ideally, I’d rather prefer to keep the same scroll position.
2) And the other thing, is that there’s an “All categories” item. For the rest of categories, there’s an “active” class applied when they are selected, but I couldn’t make this to do the same.
There’s a code example here that closely resembles the example:
But I’m not really sure in terms of good practices and such. I just based this on the other one. But will try yours as well.
What I have now missing, is this weird scroll behaviour when I click on each filter. That the scrolls resets to the topo. But I’m unsure if this is avoidable.
Well, with the anker tags, you are reloading the page when filtering. To keep the scroll position, you probably need a JS based solution, so you can listen to scroll position. That’s not really Kirby related, but frontend stuff.
This has little to do with 2024, but with the fact that you need to implement the frontend behavior. This is nothing Kirby will ever do automatically for you.
So there is no way to filter tagged pages, without changing/reloading the URL?
I’m beginning to wonder if I’d be better using the HTML details and some hardcoding
<details>
<summary>All</summary>
<p>Case study 1</p>
<p>Case study 2</p>
<p>Case study 3</p>
</details
<details>
<summary>Design</summary>
<p>Case study 2</p>
<p>Case study 3</p>
</details
<details>
<summary>Photography</summary>
<p>Case study 3</p>
</details```
Rather than always scroll to the top of the page, when using the filter, I could put an anchor tag, so the page scrolls to the filter, which is not at the top of the page.
I appreciate the scroll position will not be kept and that there will be some scrolling, but it won’t be as much, and no where near as confusing as scrolling to the top of the page.