Apologize if this is a basic question, but I think I’m stuck on a conceptual understanding of something related to tags. I have a blog loop on my home page, and I’d like to display the post’s tag linked to a page that contains posts with that tag.
I have the tag fields successfully set up in the panel and displaying correctly on my posts, however I can’t get the links to work right. Do I need to actually create a separate ‘tag’ page and template to link to such a filtered list of posts?
So far, in my templates (both on the home page template and on the single post template), I’m using this to display the tag and constructing the link:
Any ideas on what I’m missing? Thinking maybe I need to create a specific, dedicated tag.php page and template to display these? I guess I was assuming that this would still work falling back to the default.php template, but maybe not? Thanks!
I understand I need to create a controller in order to create the filtered list of posts, as explained on this post. Do I create this controller in conjunction with a new page/template, as I mention in the OP? Thanks!
Is a category page a special kind of page? Or do you just mean create a page intended to hold the filtered list of posts (like I’m trying to communicate in the OP), and then create a corresponding controller which would house the filtered loop referenced in your link?
I display a list of all posts on the home page. Each post is tagged, and I want to be able to click a tag to see a filtered list of all posts with that tag.
Then all that is left to do is add the filtering by tag in your home.php controller, like in the example I posted, at least if you use tag: sometag. If you want to use a slug for the tag, you have to do it with a route, like in the example @bart posted above.
Thanks, I don’t use a home.php controller. In fact I 'm not using any controllers yet. My site is very basic — I just use a default.php template that calls a blog_loop.php snippet for the loop. In this case would I create a default.php controller with the logic you linked to? I just tried that and it had no effect on the output of my tag links, unfortunately.
Controllers need to match the name of template they belong too, so if you home page is using home.php as its template, then the controller also needs to be named home.php.
Sounds to me like you just running the site off the default.php template that came with kirby. Is that correct?
My home page is just using default.php as it’s template, which is extremely basic, containing only a simple header, footer, and a blog loop which I’m storing in a snippet called blog_loop.php. Here’s what the loop looks like:
Note that if you set the list of posts in your template, any filtering you do in a controller will be overwritten by your template. So once you use a controller, remove your $posts definition from the template.
I solved this by integrating the Filterizr JavaScript library into my site. The page is still under construction, but here you can see that it works: https://www.sgp.de/sgpneu/referenzen
Sorry to bump this up again: I had this a while ago (Tags: list results of all existing pages), and with Kirby 2 it worked like a charm, but now, updating to Kirby 3, I cannot make it work, even if I don’t see too many differences in the code. Maybe something got lost with all the cop&paste back and forth:
What happens is that in the new result-page, coming from a tag-link on an article page, only the h3-title is displayed, but not the umlaut nor an empty space. The rest: date and titles of the articels don’t appear at all. I wonder what I am doing wrong…
If you have umlauts and spaces in your tags, you have to urlencode() and urldecode() them (and the e() helper logic also seems somehow incomplete. If you don’t want to apply and active class, you might as well remove the complete statement)