MODX:按随机选择的ID排序

时间:2017-08-22 18:46:59

标签: modx modx-revolution

我是modx革命的新手,我的任务非常奇怪。我有这个:

 [[!getPage? 
    &elementClass=`modSnippet` 
    &element=`getResources` 
    &parents=`127,106`
    &resources=`-831,-243`
    &depth=`2`
    &limit=`21` 
    &pageVarKey=`page` 
    &includeTVs=`1` 
    &includeContent=`1` 
    &tpl=`pageAllDoctors` 
    &hideContainers=`true`
    &sortby=`FIELD(modResource.id, 456,331,390,491,2756,505,634,699,941,1044,1377,1436,1449,1678,1722,1711,1828,2007,2094,2184,2324,2487,2527)`
    &where=`[{"introtext:LIKE":"%[[!searchFieldClinic? &field=`spec`]]%", "AND:introtext:NOT LIKE":"%заведу%", "AND:template:=":104}]`]]

在sortby中,我有一个首先显示的资源列表,然后是剩余的资源。唯一的问题是我不仅需要它们,而且还要随机显示它们,而不是与它们之后的其他资源混淆。

有没有办法做到这一点?

提前致谢。

2 个答案:

答案 0 :(得分:0)

&sortby='RAND()' 

http://modx.ws/getresources

Можеттак?

答案 1 :(得分:0)

解决了片段问题:

&sortby=`FIELD(modResource.id, [[!shuffleVals?&vals=`456,331,390,491,2756,505,634,699,941,1044,1377,1436,1449,1678,1722,1711,1828,2007,2094,2184,2324,2487,2527`]])`

片段

<?php
/**
 * @package shuffleVals
 */
$output = '';

$properties =& $scriptProperties;

$properties['vals'] = explode(',', $properties['vals']);
shuffle($properties['vals']);
$properties['vals'] = implode(',', $properties['vals']);

return $properties['vals'];
相关问题