Filtering front-end pages by user

Hey everyone,

Running a simple media site off Kirby 2 and we’d like to set-up a front-end statistics page that shows information about the articles such as how many a user has posted per month.

We are currently indexing the articles through $pages->index() and the users through $site->users() then running a foreach loop on $articles - however we are uncertain on how to compare the two and provide an article count.

One way of doing it would be to loop through all user and then print the number of articles:

<?php
foreach($site->users() as $user) {
  echo page('blog')->children()->filterBy('author', $user->username())->count();
}

assuming that the field is called author and that is stores the username.

Hi texnixe!

I’m aware of the above procedure - however it does not seem applicable in this case. My “authors” field found in the blueprint derives from a custom “authors” page rather than $users.

Thus an “author” of an article is not necessarily an actual user under “User Management”.

Ok, you didn’t say that above, then you have to loop through your authors instead of the $site->users().