Hey, thanks for the reply!
Yes, but you need to set multilevel=1 for that to work at the moment.
I still need to add a check to say if there are commas in the list, use the advanced method...
It worked great that way, but I wanted to improve a bit and made some changes
I have posted my code ...
$multilevel is used just to force NO-multilevel, the rest goes all automatically.
First
$startID is cleaned, just numbers are kept back and commas. Multiple commas, or commas on first/last position are also removed. If user forces to use no multilevel with
&multilevel=0 just the first ID is used, the rest including commas is removed. Else
$multilevel is automatically set to 1 and all IDs are used.
<?php
//Define the pattern to search for
$pattern = array( '`([^,\d])`', //All chars except commas and numbers
'`(,)+`', //Multiple commas
'`^(,)`', //Comma on first position
'`(,)$`' //Comma on last position
);
//Define replacement parameters
$replace = array( '',
',',
'',
''
);
//Clean startID (all chars except commas and numbers are removed)
$startID = preg_replace( $pattern, $replace, $startID );
//If multilevel is forced to zero... keep first ID, remove the rest
if(isset($multilevel) && $multilevel == 0)
$startID = preg_replace( '`^([\d]+)(,)?(.)*`', '$1', $startID );
else
$multilevel = 1;
?>
Put this just before:
<?php
$resourceparent = isset($startID) ? $startID : $modx->documentIdentifier;
// the folder that contains post entries. separate multiple folders by comma when multilevel is equal to 1.
?>
The following code can be removed:
<?php
$multilevel = isset($multilevel)? $multilevel : 0;
// automatically detect and show children to the descendentDepth level
?>
I hope you don’t get mad because of the changes I made. If you want to use this for the snippet, you are welcome.
Tested it a bit with 4 level deep folders, and it works fine (at least for me).
Later Edit: Quick example, if you enter bad IDs like "
$%^,,,,3,5,8..,6abc,,,,", the code will clean the string and you have the corect IDs "
3,5,8,6"
Cheers, Boby.