Children of Children of Children of

Okay, so I have run into an interesting thing in my coding that I cannot explain so hopefully someone else may.

I have the following loop(s) in my code and it works as expected. It generates an array that I later use to populate a History split into Years (if not current Year) and Months (for the current year).

  // posts by month if current year, by year otherwise
  // go through each blog
  // sort through their years (we count for past years)
  // sort through their months if this year
  $results = array();
  $all_blogs = $site->find('blog')->children()->visible();
  foreach ($all_blogs as $blog) {
    $blog_entries = $blog->children();
    foreach ($blog_entries as $blog_year) {
      if ($blog_year->uid() == date("Y")) {
        $blog_month_entries = $blog_year->children();
        foreach ($blog_month_entries as $blog_month) {
          $monthName = $blog_month->uid();
          if(!isset($results["Months"][$monthName])) { $results["Months"][$monthName] = 0; }
          $results["Months"][$monthName] += $blog_month->children()->count();                  
      } else {
        if (!isset($results["Years"][$blog_year->uid()])) { $results["Years"][$blog_year->uid()] = 0; }
        foreach ( $blog_year->children() as $blog_month ) { $results["Years"][$blog_year->uid()] += 1; }

Now my problem … if I modify the following lines

$blog_entries = $blog->children();
$blog_month_entries = $blog_year->children();

And add ->visible() to them, they return empty objects. At the moment everything is visible, however I obviously want to deal with invisible entries in the future.

Is there something glaringly obvious?

Thanks in advance,

I’m a bit surprised that this code works and the uid() is supposed to return the year. How do you name your folders?

Oh sorry … the file structure is important too :smile:


So an entry would be found at Site/Blog/Testing/2015/06/08


The problem is, the way Kirby works, you can’t have folder names that start with a number, because numbers (or the absence of numbers) are used to flag pages as visible/invisible.

1 Like

Slap to the forehead!!

You know I did not even think of that at all … can I do something like 1-08? Because technically that is what I want.


If you want to use the panel, you definitely can’t. If not, I’m not sure, but it might work.

Okay cool … I will have to come up with some kind of naming scheme then and work out how to “pretty URL” the entires into the look I was after /Year/Month/Day

Thank you very much for your help,

The way Kirby works, it makes more sense to have a flat folder structure. You can however use the router to mimic more of a Wordpress style scheme,

1 Like

Thank you for that!

So many things to learn about Kirby … it just gets better every little task I have to complete.

The load time for the website is faster by degrees.