Auto increment IDs in Kirby
I built an auto increment ID logic for kirby pages using hooks. The following code is self explaining:
// in the plueprint
// ...
// ... your bluprint rules
// ...
aiid:
label: Auto Increment ID
type: number
readonly: true
// site/config/config.php
// update the created page with the ID after creating the page
kirby()->hook('panel.page.create', function($page){
// get the actual id from an txt file in the kirby root folder
$aiid = intval(file_get_contents(kirby()->roots->index().'/aiid.txt'));
$aiid++;
// save the incremented id
file_put_contents(kirby()->roots->index().'/aiid.txt', $aiid, LOCK_EX);
// update the created kirby page
$page->update(array('aiid' => $aiid));
});
Use Case Google News
To support the google news bot you can put an aiid in the url. I will use the ID for this case in a custom URL:
my-domain.de/news/1001-the-uri-to-my-news-article
Extract from the technical guidelines of google news
Article URLs. To make sure we only crawl new articles, please make sure your URLs are unique with at least 3 digits, and are permanent.
https://support.google.com/news/publisher/answer/40787?hl=en
Any ideas to improve/extend it? I am glad about your proposals.