如何使用getResources从资源树中的多个节点获取父资源~只有一次~即我有一个getResources调用:
[[!getResources?
&parents=`738,746,1222, 748, 1216, 805, 806, 807, 3401`
&tpl=`SecondaryUpdatesHomePageTpl`
&limit=`3`
&includeTVs=`1`
&processTVs=`1`
&hideContainers=`1`
&includeContent=`0`
&depth=`1`
&sortby=`{"createdon":"desc"}`
]]
如果 &parent id 是要搜索的树,则每个父级中可能有多个新资源。我需要获取资源来返回 &父项的父资源"但只有一次"
例如,如果父母 738、748. 807 和 3401 各自有 4 或 5 个新资源,我不希望 738 被返回 3 次,我需要 ~父级~738、748 和 807 返回。
关于如何做到这一点的任何想法?[模组革命 2.2.12]
看了一会儿之后,我想你基本上只需要做另一个 getResources 调用,将 &resources 参数设置为第一个 getResources 调用的修改输出。请注意,我从嵌套的 getResources 调用中删除了包含电视。
更改 getResources 中的 TPL 以输出父项,后跟逗号,([[+parent]],
)基本上生成一个逗号分隔的 ID 列表。将 getResources 调用的输出馈送到另一个具有正确 TPL 的调用中(辅助更新主页 Tpl)
[[!getResources?
&resources=`[[!getResources?
&parents=`738,746,1222, 748, 1216, 805, 806, 807, 3401`
&tpl=`CSVListOfParentsTPL`
&limit=`3`
&hideContainers=`1`
&depth=`1`
&sortby=`{"createdon":"desc"}`
]]`
&tpl=`SecondaryUpdatesHomePageTpl`
&includeTVs=`1`
&processTVs=`1`
]]
像这样嵌套显然不是最有效的解决方案,另一种方法是编写您自己的自定义代码段,该代码段>$modx或多或少与您提供给 getResources 的参数相同,但直接获取父级而不是进行第二次旅行来获取它们。
尝试使用新代码段:
[[unikids? &input=`1,5,6` $depth=`5`]]
和狙击代码:
<?php
$array_big = array();
$inputids = explode(",",$input);
foreach($inputids as $inputid) {
$array_ids = $modx->getChildIds($inputid,$depth,array('context' => 'web'));
/// add to master array
$array_big = array_merge ($array_big, $array_ids);
}
$output = implode(",",array_unique($array_big));
return $output;
?>
这个狙击手将唯一的ID输出到你的getResources参数:
[[!getResources?
&resources=`[[unikids? &input=`1,5,6` $depth=`5`]]`
&tpl=`SecondaryUpdatesHomePageTpl`
&includeTVs=`1`
&processTVs=`1`
]]