MODX:按随机选择的 ID 排序
MODX: sort by random selected ids
我是 modx revolution 的新手,我的任务很奇怪。我有这个:
[[!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 中,我有一个要首先显示的资源列表,然后是其余资源。唯一的问题是,我不仅需要它们排在第一位,而且还需要它们随机显示,而不是与它们之后出现的其他资源混淆。
有什么办法吗?
提前致谢。
&sortby='RAND()'
也许是这样?
解决了片段问题:
&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'];
我是 modx revolution 的新手,我的任务很奇怪。我有这个:
[[!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 中,我有一个要首先显示的资源列表,然后是其余资源。唯一的问题是,我不仅需要它们排在第一位,而且还需要它们随机显示,而不是与它们之后出现的其他资源混淆。
有什么办法吗?
提前致谢。
&sortby='RAND()'
也许是这样?
解决了片段问题:
&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'];