如何按指定顺序对Modx getResources进行排序?

时间:2015-05-10 00:41:57

标签: modx modx-revolution modx-resources modx-getresources

我们如何按照'resources'属性中指定的顺序对modx getResources调用进行排序?

我有:

[[!getResources? 
    &parents=`-1`
    &resources=`[[*HomePageUpcomingEvents]]` 
    &tpl=`SecondaryUpdatesHomePageTpl` 
    &limit=`3` 
    &showHidden=`1` 
    &includeContent=`1` 
    &includeTVs=`1` 
    &processTVs=`1`
    ]]

其中:HomePageUpcomingEvents是一个以逗号分隔的id列表,我想按特定顺序显示:6405,6154,6991

1 个答案:

答案 0 :(得分:1)

https://rtfm.modx.com/extras/revo/getresources - 在提问之前阅读文档。

&sortby=`FIELD(modResource.id, 4,7,2,5,1 )`

在你的情况下,它将是

&sortby=`FIELD(modResource.id, [[*HomePageUpcomingEvents]] )`

<强> UPD

三个例子:

[[!getResources?
    &parents=`-1` 
    &resources=`1,2,3` 
    &sortby=`FIELD(modResource.id, 3,2,1 )`
    &tpl=`@INLINE [[+id]]`
    &showUnpublished=`1` 
    &showHidden=`1` 
    &showDeleted=`1`
]]
<hr>
[[!getResources?
    &parents=`0` 
    &resources=`1,2,3`
    &sortby=`FIELD(modResource.id, 3,2,1 )`
    &tpl=`@INLINE [[+id]]`
    &showUnpublished=`1` 
    &showHidden=`1` 
    &showDeleted=`1`

    &sortdir=`ASC`
]]
<hr>
[[!getResources?
    &parents=`0` 
    &resources=`1,2,3` 
    &sortby=`FIELD(`modResource`.`id`, 3,2,1 )`
    &tpl=`@INLINE [[+id]]`
    &showUnpublished=`1` 
    &showHidden=`1` 
    &showDeleted=`1`

    &sortdir=`DESC`
]]

三个输出:

1
2
3
<hr>
3
2
1
<hr>
1
2
3