First of all, I need to know what sort of error you get? Secondly, I don’t have a crystal ball that lets me read your code from where I am , so I have no idea what could be going wrong…
Also, what are your plans with the archive page? Do you want to move pages there from the blog once they are outdated? (You can’t move pages in the Panel).
Thanks, but it doesn’t work, I still can’t see anything.
Anyway, first of all, turn on debugging in your config.php.
c::set('debug', true);
Once you’ve done that, there should be a more telling error message. If you still can’t find your error, then maybe you want to make up your mind and post your code.
How do you write your blog posts? In the Panel?
The problem with moving stuff around is that the URL for your articles will change if you move them into another folder. So maybe this is not such a great idea? Why do you want to move post anyway? 5 to 10 posts in a folder is not really a lot. If you don’t want to show old posts, you might as well filter them out instead of moving them around.
And one more thing: make sure that your text file, the blueprint and the template have the same name, either archiv or archive, otherwise Kirby will fall back to the default template.
The error is said to be in <?php if($articles->count()): ?> in my template (see downstairs)
Yes, I write my posts in the panel. And you are probably right - filtering old ones out is better than moving. But where do I filter them to? Still a different page, right?
And you were right - there was a typo in the “achiv(e)” YAML file. Here is it:
Yes, you can have an archive page. In the template of the archive page, you would then filter all articles by date older than whatever.
I can only guess what is wrong with $articles->count() without the actual error message about which you are still very secretive, but you probably haven’t defined $articles anywhere?
The code of the archiv page/ template is a copy of the code in the template „blog“.
The Blog works, it fetches all blogposts and displays them. So the $articles must be definded somewhere - no? I thought, I would basically get the same output like the blog page and could then see how move on from there. Like how one can display just older post on the archive page.
If you have just copied the blog controller, $articles will not return anything because $page in this case is the archive page which does not have any subpages.
You would have to replace $page->children() etc. with page('blog')->children() etc. and take it from there. After that you can filter by date. There’s a nice little Cookbook recipe all about filtering that should hopefully answer all your questions (if not, I promise I will update it).
Are controllers necessary: no, but they are are good way to keep the logic separate from the HTML.
Just to complete this:
Adding this one line at the right place to the stuff that was already in the controller took me hours of fun (kind of). And it works!
Great! You are a true fighter! Now you only have to find a way to make this more dynamic, i.e.filter all articles that are older than 2 weeks, for example…
I tried. Maybe every possible combination from the examples of the docs and some googling for help, but - not having luck. Doing it wrong every single time. Speaking of it,
time())
is what I want to use, `cause it means “now”, right?
What I want to say is “filter by date using current date whatever “now” is at that moment, substract 1 year”. I read that there is “now” in php as well, but it doesn’t work either, so the best wrong code that I can come up with is: