You wat to create a menu item which redirects to its first child
You want to have an easy to remember url which links to an existing page
You want to have redirects which can be edited by editors within the panel
Creating editable page redirects with Kirby is really easy …
###Step 1: Blueprint
site/blueprints/redirect.php
title: Redirect
pages: true
files: false
fields:
title:
label: Title
type: text
redirect:
label: Redirect to page
type: page
Step 2: Controller
site/controllers/redirect.php
<?php
return function($site, $pages, $page) {
if (!$page->redirect()->empty()) {
// if 'redirect to page' is set, go for it
$redirect = $page->redirect()->url();
}
elseif ($page->children()->visible()->count()) {
// else if page has visible children, redirect to the first one
$redirect = $page->children()->visible()->first()->url();
}
else {
// fallback: redirect to homepage
$redirect = $site->homePage()->url();
}
return array(
'redirect' => $redirect,
);
};
OK I see, I change the page template to Redirect. I have one problem though, I am redirecting my Articles page to the homepage. When I select a tag like: http://localhost/articles/tag:kirby that also gets redirected to the homepage. Is there a way to prevent that?
Glad you got it working. The plugin doesn’t consider params at the moment and it probably won’t do it in the future. I think this is kind of an edge case and it’s almost impossible to find a general solution for this which works for all kind of params / use cases.
Instead I would use a custom template (maybe “articles”) for this. If params are set, display the stuff you want and if not redirect to the homepage.