ModX 革命:按文件夹菜单索引排序,然后按元素菜单索引排序



我是ModX的新手。我的资源彼此嵌套在一起,如下所示:

resource1
- resource1-child1
- resource1-child2
resource2
- resource2-child1
- resource2-child2

和这个代码:

[[!getResources? 
&includeContent=`1` 
&parents=`[[pdoField? 
&id=`[[*id]]` 
&field=`id` 
&topLevel=`4`]]` 
&resources=`-[[*id]]` 
&includeTVs=`1` 
&processTVs=`1`
&sortby=`menuindex`
&sortdir=`asc`
&depth=`10` 
&limit=`100` 
&tpl=`allDoctors` 
&where=`{"template:=":104}`]]

但由于某种原因,它不会按菜单索引对元素进行排序。看起来它根本不会对任何内容进行排序,除非我从父资源中提取子级。如何让它按文件夹菜单索引和子菜单索引对所有内容进行排序?提前致谢

通过创建一个名为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;

并像这样整理:

[[!getResources? 
&includeContent=`1` 
&parents=`[[pdoField? 
&id=`[[*id]]` 
&field=`id` 
&topLevel=`4`]]` 
&resources=`-[[*id]]` 
&includeTVs=`1` 
&processTVs=`1`
&sortby=`[[!getResourcesTree? 
&parents=`[[pdoField? 
&id=`[[*id]]` 
&field=`id` 
&topLevel=`4`]]` 
&depth=`100`]]`
&sortdir=`asc`
&depth=`10` 
&limit=`100` 
&tpl=`allDoctors` 
&where=`{"template:=":104}`]]

最新更新