0

我们如何按照“资源”属性中指定的顺序对 modx getResources 调用进行排序?

我有:

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

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

4

1 回答 1

3

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
于 2015-05-10T01:57:50.057 回答