Blogposts in subfolders (year/month) don't show up

Hi there.

I have a blog folder with subfolders for years and months. But the articles inside the subfolders won’t show up on my blog-homepage.

My folder structure looks like this: blog/2018/05/20180525-my-blog-post

In my blog.php template i tried it this way …:
<?php foreach($page->children()->visible()->flip()->paginate(10) as $article): ?>

… and that way:
<?php foreach($page->grandChildren()->visible()->flip()->paginate(10) as $article): ?>

Can anyone point me in the right direction?

Children would be the pages inside blog, grandchildren the children inside the year folders, so you would have to go one level deeper.

I’d fetch the page index and filter by template:

$posts = $page->index()->visible()->filterBy('template', 'post'); //or whatever your template
1 Like

Thx. You just saved my sanity.

I just came across this, as I have the same issue. How would I have to embed that line in a foreach loop? In Kirby3, of course :grin:.

Thanks in advance for your help,

$posts = $page->index()->listed()->filterBy('template', 'post'); //or whatever your template
foreach ($posts as $post) {
  // do stuff

Thanks a million! Works like a charm.

All the best,