Here is a simple plugin to automatically redirect top-level parents with children to the first child (it is the same as adding FirstChildRedirect to the top-level parent). If top-level has no ’active’ children than it will do nothing.
The most accurate name would have been AutoFirstChildRedirectIfTopLevel...but that was too long so autoFolders it is
Create a new plugin, paste in this code and select OnParseDocument system event...and save.
// <?php
// automatically redirect to first child from top-level document.
// based on FirstChildRedirect snippet
$id = $modx->documentIdentifier;
$parent = $modx->documentObject['parent'];
// check if top-level
if($parent === '0'){
// check if has active children
$children= $modx->getActiveChildren($id, 'menuindex', 'ASC');
if((!$children === false) && ($children['0'] != '')){
$firstChildUrl = $modx->makeUrl($children['0']['id']);
$modx->sendRedirect($firstChildUrl);
}
}
return;
Can improve this in many ways...for example can have it check if there is content in the parent and only redirect if not, or can go deeper in the menu, or can have a TV do override the action.