Quote from: OpenGeek at Dec 28, 2009, 11:49 AM
At the current time, you can’t sort the results of getResources in a hierarchical tree like you can with Wayfinder. I am working on adding advanced custom sorting capabilities though for the next release of this snippet, which will allow this.
Hi!
Old post I know, but still not posibble order by tree?
If I missed something? I try with menuitem but that not preserve tree order.
That’s why I created an custom snippet to be able to sort the resources by tree with getResources (most important snippet for Revo).
Call it getResourcesTree
<?php
if (!function_exists('multiarray_keys')) {
function multiarray_keys($ar) {
foreach ($ar as $k => $v) {
$keys[] = $k;
if (is_array($ar[$k]))
$keys = array_merge($keys, multiarray_keys($ar[$k]));
}
return $keys;
}
}
$parents = (!empty($parents) || $parents === '0') ? explode(',', $parents) : array($modx->resource->get('id'));
$depth = isset($depth) ? (integer) $depth : 10;
$tree = $modx->getTree($parents, $depth);
$tree = multiarray_keys($tree);
$tree = implode(',', $tree);
$tree = 'FIELD(modResource.id, ' . $tree . ')';
return $tree;
And call getRessources like this:
[[!getResources?
&parents=`19,25`
&tpl=`myTpl`
&sortdir=`ASC`
&limit=`50`
&sortby=`[[!getResourcesTree? &parents=`19,25` &depth=`100`]]
`]]
I think that depth from getResources, and depth from getResourcesTree($modx->getTree) do not have the same behavior.