Add authors to your pages
Tie pages to a person. Create an author system for your blog posts.
Assigning one or more people to pages like posts or projects is a common use case and Kirby's user system in combination with the users field is a perfect fit for this.
Authors can be created as Kirby users. A Kirby user can have different roles, and you can store any information in a user profile, including a profile picture.
Before you add new users as authors, think about what information you want to store for these users. We can then set out to create a blueprint for our authors.
In this example, let's create an
author.yml blueprint, which we store in
/site/blueprints/users. In our user blueprint, let's define some fields:
Since name and email are default fields, we don't have to define them here. With this blueprint, we now have defined a new user role and can start adding authors with this role.
In the Panel, this setup will now look like this:
This can be extended to a full database of author contact details and more, depending on your use case.
Now that we have created a blueprint for the user and added some users in the Panel, we need a way to select one or more authors in our posts. Kirby has a users field that comes in handy for this purpose. Let's set it up in our
In this example we have defined a sidebar with some meta data fields and an authors field. The authors field has some default settings and options you can find in the users field docs. Here we have kept it simple and only set the
multiple option to
false, because we only want to select a single author.
In the content file
article.txt, the selected user is stored in
Title: Content in Kirby ---- Date: 2017-08-04 00:00 ---- Text: Some great text ---- Author: - firstname.lastname@example.org
You can now fetch the author data in the article template. This is just a basic example of how the article template could look:
This is very extendible and can give your articles a nice personal touch.
You can also build a list of all authors that have created an article and fetch their articles:
Create a new folder
authors with an
authors.txt file and an
In that template you can fetch all authors from the articles and build a list out of it.
Each author will show up on http://yourdomain.com/authors with the user avatar and a list of articles they have written. This can be extended with more info about each author or more info about each article.