【问题标题】:How to sort Modx getResources in a specified order?如何按指定顺序对 Modx getResources 进行排序?
【发布时间】:2015-07-20 17:00:09
【问题描述】:

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

我有:

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

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

【问题讨论】:

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


    【解决方案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
    

    【讨论】:

    • 这将根据您传递给它的列表中的 id 对资源进行排序 - 而不是您传递 id 的顺序。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-18
    • 1970-01-01
    • 2022-01-24
    相关资源
    最近更新 更多