2014-04-05 45 views
0

如何使用getResources摆脱几个节点父资源的资源树〜只有一次〜也就是我有一个getResources拨打:如何使用modx 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"}` 
]] 

凡&父母ID是要搜索的树木,有可能是每个家长的几个新资源。我需要获得资源来回报父母&项目“但只有一次”

因为如果父母738,748。807 & 3401每个下面有4个或5个新的资源,我不想做738例父资源得到3次返回,我需要~738,748,&807的父母返回。

有关如何做到这一点的任何想法? [modx revolution 2.2.12]

+2

很难理解,而不截图你的资源树。 – Vasis

回答

0

看了一会儿之后我猜你基本上只需要做另一个getResources调用,将&资源参数设置为第一个getResources调用的修改输出。请注意,我从嵌套的getResources调用中移除了includeTV。

更改您的getResources中的TPL以输出父母后跟逗号(([[+parent]],)),基本上会生成逗号分隔的ID列表。喂你getResources的输出调入另一个具有正确的TPL(SecondaryUpdatesHomePageTpl)

[[!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` 
]] 

嵌套像这显然不是最有效的解决方案,另一种方法是编写自己的自定义代码片段,使一个$镆铘 - >或多或少地查询给出getResources的相同参数,但是直接获取父母而不是第二次获取它们。

+0

看起来像这样仍然会多次返回同一父元素。我将不得不在getresources上使用runSnippet,然后自己过滤结果。不过谢谢。 –

0

尝试使用新的代码片段:

[[unikids? &input=`1,5,6` $depth=`5`]] 

和snipet代码:

<?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; 

?> 

这snipet输出唯一的ID,以您的getResources parametr:

[[!getResources? 
    &resources=`[[unikids? &input=`1,5,6` $depth=`5`]]` 
    &tpl=`SecondaryUpdatesHomePageTpl` 
    &includeTVs=`1` 
    &processTVs=`1` 
]]