How to add authors to your articles
I just ran through the backlog of support requests for this year and found an interesting question: How do you add different authors to articles in a Kirby blog?
There's no built-in way to work with multiple authors, but it's quite easy to setup a nice little system for your publisher team and this is how:
The authors folder
Create a new, invisible authors folder. This will hold all the data and profile pictures of your authors. Each author gets their own subfolder and an
The author.txt files can contain any data for each author.
name: John Doe ---- bio: John is an awesome author with years of experience ---- email: firstname.lastname@example.org ---- website: http://john.doe.com ---- twitter: http://twitter.com/johndoe
I think it's easy to understand how this can become a full database of author contact details and more, but it's of course up to you to just enter the basic information about each author, which will be visible on the site.
Your articles text files
Each article in your blog will get its own article.txt (you can find more about this in the blog tutorials). Those
article.txt files normally should look like this:
title: My awesome blog post ---- date: 2013-12-30 ---- text: This is the last blog post for this year
To link the author data, all you need to do is to add the author's folder name:
title: My awesome blog post ---- date: 2013-12-30 ---- text: This is the last blog post for this year ---- author: john-doe
Your article template
Fetching the author data in the article template is easy.
This is just a basic example of how the article template could look:
<?php snippet('header') ?> <article> <h1><?php echo $page->title()->html() ?></h1> <time><?php echo $page->date('d.m.Y') ?></time> <?php echo $page->text()->kirbytext() ?> <?php $author = $pages->find('authors/' . $page->author()) ?> <aside class="author"> <h1><?php echo $author->name() ?></h1> <figure> <img src="<?php echo $author->images()->first()->url() ?>"> </figure> <?php echo $author->bio()->kirbytext() ?> <h2>On the web:</h2> <ul> <li><a href="<?php echo $author->website() ?>">Website</a></li> <li><a href="<?php echo $author->twitter() ?>">Twitter</a></li> </ul> </aside> </article> <?php snippet('footer') ?>
This is very extendible and can give your articles a nice personal touch.
The authors list
Additionally it's super easy to build a list of all authors and fetch their articles.
Just create an
authors.txt file in the
authors content folder and add an
In that template you can loop through all subfolders of the authors folder and build a list out of it.
<?php snippet('header') ?> <?php $articles = $pages->find('blog')->children() ?> <h1>Authors</h1> <?php foreach($page->children() as $author): ?> <article class="author"> <h1><?php echo $author->name()->html() ?></h1> <figure> <img src="<?php echo $author->images()->first()->url() ?>"> </figure> <ul class="articles"> <?php foreach($articles->filterBy('author', $author->uid()) as $article): ?> <li><a href="<?php echo $article->url() ?>"><?php echo $article->title() ?></a></li> <?php endforeach ?> </ul> </article> <?php endforeach ?> <?php snippet('footer') ?>
Each author will show up on http://yourdomain.com/authors with the profile picture and a list of articles he or she has written. This can be easily extended with more info about each author or more info about each article.
It's not a full-blown authoring system with permissions or an editing workflow. It's really just a nice and simple way to add author information to your articles and pages without having to reenter it for each article.
Let me know if you use something similar on your Kirby site. I'd love to add it here as a reference.