Setting up Kirby Part 1: Microblog
![](https://inhji.de/media/pages/blog/setting-up-kirby-part-1-microblog/95efb543a9-1703198643/david-travis-5byxxawhoqg-unsplash-300x.jpg 300w, https://inhji.de/media/pages/blog/setting-up-kirby-part-1-microblog/95efb543a9-1703198643/david-travis-5byxxawhoqg-unsplash-600x.jpg 600w, https://inhji.de/media/pages/blog/setting-up-kirby-part-1-microblog/95efb543a9-1703198643/david-travis-5byxxawhoqg-unsplash-900x.jpg 900w, https://inhji.de/media/pages/blog/setting-up-kirby-part-1-microblog/95efb543a9-1703198643/david-travis-5byxxawhoqg-unsplash-1200x.jpg 1200w, https://inhji.de/media/pages/blog/setting-up-kirby-part-1-microblog/95efb543a9-1703198643/david-travis-5byxxawhoqg-unsplash-1800x.jpg 1800w)
I have added a plugin to my kirby site which changes the slug and the title of any page created with the micropost
template. This way, I can create a post in the Micro section and the slug and title will be set to a date-string. This is a good first step of adding a microblog to kirby.
The plugin consists of a class:
class MicroblogPage extends Page
{
public static function create(array $props): Page
{
$timestamp = time();
$props['slug'] = "{$timestamp}";
return parent::create($props);
}
}
and a plugin which registers that class and a hook:
Kirby::plugin('inhji/microblog', [
'pageModels' => [
'micropost' => MicroblogPage::class
],
'hooks' => [
'page.create:after' => function ($page) {
if ($page->template()->name() == 'micropost') {
$timestamp = time();
$newTitle = date('Y-m-d H:i', $timestamp);
try {
$page->changeTitle($newTitle);
} catch(Exception $e) {
echo $e->getMessage();
}
}
}
]
]);