Adding 1 or more Users as Authors

Okay, I’ve followed the cookbook instructions as best as I can a few times and I don’t think this article explains completely how to go about this task:

I think being more specific with describing the steps to go about this would be more helpful.
Is there a better walkthrough about adding Users as Authors and linking to possible Author pages, for example?
Thanks in advance…

Where did you get stuck?

Well, I think I got pretty far along a few times, but then I started tinkering to add Author pages and that fell flat.
In this case, perhaps creating Authors and Author pages from the Users is done differently. I assumed that I could create and link to Author pages and list all of their Articles on those pages. I’m still struggling with that.
But perhaps I need full walkthroughs instead of general recipes in a cookbook.

You can link to either Kirby users using the users field. Or you can link to one or multiple authors that are subpages of an authors (or whatever you want to call it) page. In the second case, you cannot use a users field but have to use a multiselect field.

The cookbook recipe you mentioned above refers to linking to authors that are created as Kirby users, not as subpages in the content folder.

1 Like

I did see some action when I used the multiselect in testing. That’s an interesting caveat. I’ll try that.

Re: Cookbook recipe: Ah, that’s perhaps where I’m misguided. Is it possible to do both? …have Author pages that reference Users on the site? Or do panel users have to be separate from Author pages that reference Content data about themselves? That’s probable. Okay.

Why would you want to do that?

I suppose to allow users to log in and create a blog post for themselves… or something similar.
But yeah, I understand that’s crossing the streams perhaps.

I just don’t see the purpose. Maybe you can explain it a bit better.

Why not create all your authors as Kirby users? What would be your use case for having authors that are not Kirby users? If you want to include users with no Panel access that create content from the frontend, they could still be Kirby users with a different role.

Of course, you could also mix Kirby users and authors from subpages of an authors page in a multiselect field if you wanted to.

Ohhhhh. Apologies.
That is in fact what I’d prefer. To have Users also be Authors on the site (instead of maintaining two places where data lives). Apologies if I hadn’t explained myself correctly.
However I can’t seem to make it happen. Should there be an Page/Authors.yml that references a Users/author.yml?
In essence, when I read the Cookbook entry about adding Authors to a site, THIS is exactly what I thought it meant. But it doesn’t do all of that. If it does, it doesn’t communicate the steps properly i think, hence my post here about it.

Let’s assume you wanted two different user roles, one with access to the Panel, one without.

For that purpose, you would create two different user roles in site/blueprints/users, for example

  • author.yml and
  • frontendauthor.yml

The frontendauthor role would set permissions so that this user role cannot log in to the Panel by setting the permissions accordingly:

title: Frontendauthor
    panel: false

On the frontend, you can fetch these different user types by role.

However, I’m still not sure what you want to achieve really.

Yeah, this is great. Thanks, @texnixe!
My main goal is multiple authors, what permissions they have is not important.
So, if I wanted individual Author Pages to show the Author’s bio and all of the Articles they’ve written, how would this be constructed?

Since Kirby users can have fields in the same way that subpages can, you would create one or more blueprints for each user role.

You would then use a users field to link blog posts to your authors.

If you want to have user pages that list their articles, the best way to go about that would be to create an authors page (but without subpages for authors) and then use a route to link to the individual users and list their articles.

Your route would look something like this and return the authors page with the user as variable you can then filter by in your authors.php controller:

'routes' => [
      'pattern' => 'authors/(:any)',
      'action'  => function ($user) {
         $user = kirby()->users()->findBy('username', $user);
         if ($user) {
            $data = [
                  'tag' => $user,
            return page('authors')->render($data);
1 Like

Ah haaaaa. The Route. That seems to be the part I’m missing. I’ll have to learn this.

The structure I’m going for seems common, but perhaps it’s not that common:
-lists all authors with links
-lists all articles by this author with links
-lists all articles with links
-one article
-lists all tags with links
-lists all content/articles under this tag with links

Thanks, again, Sonja!

I have added an (untested) route example above.

If you need more help with actually implementing this, feel free to ask.

IMO, the problem is not that the cookbook article is not specific enough, but it doesn’t fit your use case.

On a side note: Apart from using routes, you could also use a page model that returns the Kirby users as virtual children of the authors page…

1 Like

I’m not sure how to setup routes at this point, but I have looked into it. I’m not an PHP dev, but tinkering got me this far. I’ll likely go with making people as another section of the site instead of via Users. Thanks for your help on this.

This is correct.
I’d looked at making virtual children, too, but that defeats the purpose of having a filebased data collection for me. Also, my brain won’t fully wrap around it, so there’s that! :wink:

Here is an example proof-of-concept thingy of using Kirby users as children of the authors page.

Panel access:
pw: testtest

Check out the AuthorsPage model in /site/models/authors.php

Note that the code is lacking some checks like if a page exists etc., so please regard this as quick and dirty.

This allows you to define authors with permissions and nevertheless have author pages without using routes. The fields (actually only the email field in this case) for the authors are made readonly to not mess with the user content.

Also, you would have to fine-tune the blueprint options for the virtual children etc.

1 Like

Thank you so much, Sonja. This is above and beyond the support I’d expect for the cost of the app.

Very interesting.
So, I’m looking at the /site/models/authors.php which is interesting. So this is the glue that combines the Users as Authors to the Authors page, correct? This’ll work great.

Excactly. If you look at the authors.php template, you see that you can now link to the individual users as if they were real subpages. And if you click on a link in the authors page, you will automatically go to a single user page.

There are several parts to it. The model is main element, then there is the part that filters the articles by author in /site/templates/author.php.

As regards the fine-tuning:

The page options for the users are pretty useless, you don’t want to duplicate users, change their URL etc. so you would actually have the following settings in /site/blueprints/pages/author.yml:

  changeTitle: false
  changeSlug: false
  changeStatus: false
  changeTemplate: false
  delete: false
  update: false
  duplicate: false

You can achieve the same with a route, but the virtual authors are an interesting alternative with many options.

1 Like

A post was merged into an existing topic: Multiple authors to a blog post in kirby 3