I think I’ve seen this before while starting out in Evo but I can’t figure out where I’ve seen it. Basically, if I had a homepage that had several child docs in it, if I go to the homepage directly, it’ll automatically redirect me to the latest child doc I entered. Does anyone know if this feature is indeed supported in either MODx Evo or Revo?
Cheers,
Les
-
☆ A M B ☆
- 24,524 Posts
There’s the FirstChildRedirect snippet, which redirects to the first child according to the menuindex values. That could be modified to get the latest child by using the resource IDs of the children instead:
$docid = (isset($docid))? $docid: $modx->documentIdentifier;
$children= $modx->getActiveChildren($docid, 'menuindex', 'ASC');
if (!$children === false) {
$firstChild= $children[0];
$firstChildUrl= $modx->makeUrl($firstChild['id']);
} else {
$firstChildUrl= $modx->makeUrl($modx->config['site_start']);
}
return $modx->sendRedirect($firstChildUrl);
I believe you could also use this if you don’t want to mess with the menuindex settings:
$children= $modx->getActiveChildren($docid, 'createdon', 'ASC', 'id,pagetitle,createdon,description,parent,alias,menutitle,class_key,context_key');
You can remove any fields you don’t need from the last argument.
Hi Bob,
Thanks for the input, too. I’ll give this a try when it’s implementation time. The values - id,pagetitle,createdon,description,parent,alias,menutitle,class_key,context_key - are these table fields?
Cheers,
Les
-
☆ A M B ☆
- 24,524 Posts
class_key and context_key sound like Revo things; but yes, those are all fields for the site_content table.
Quote from: sottwell at Dec 02, 2010, 02:07 AM
class_key and context_key sound like Revo things; but yes, those are all fields for the site_content table.
Susan is right (as always) about class_key and context_key. You might have to remove those for it to work in Evolution.
The defaults in Evolution for that argument are: ’id, pagetitle, description, parent, alias, menutitle’
I don’t think any of them are required except the one you’re sorting by.
All right, and I just put this snippet call in the parent doc whose latest child I want the system to jump to?
Quote from: diatomin at Dec 03, 2010, 01:21 AM
All right, and I just put this snippet call in the parent doc whose latest child I want the system to jump to?
That’s right.