<?php
/* set parameters */
$parent = (!empty($parent) || $parent === '0');
$depth = isset($depth) ? (integer) $depth : 1;
$tpl = isset($tpl) ? $tpl : 'chunkname';
/* get child ids of parent */
$categories = $modx->getChildIds($parent, $depth);
/* new query */
$criteria = $modx->newQuery('modResource');
/* retrieve only published, hidden, and isContainer*/
$criteria->where(array(
'published' => true,
'deleted' => false,
'hidemenu' => true,
'isfolder' => true,
'id:IN' => $categories,
));
$criteria->sortby('pagetitle','DESC');
/* get the resources as xPDOObjects */
$categories = $modx->getCollection('modResource',$criteria);
/* output */
$output = array();
foreach ($categories as $category) {
$phs = array_merge(
array('count' => $category->hasChildren()),
$category->toArray()
);
$output[] = $modx->getChunk('tpl',$phs);
}
$output = implode("\n",$output);
return $output;
?>
$debug = (boolean) $modx->getOption('debug', $scriptProperties, false);
$modx->log(modX::LOG_LEVEL_ERROR, '[mysnippet] Some error message');
$myChunk = $modx->getOption('tpl', $scriptProperties, 'tpl');
...
$output[] = $modx->getChunk($myChunk,$phs);
// $modx->getOption(Key/Name, Array or Null, Default Value);
$myChunk = $modx->getOption('tpl', $scriptProperties, 'tpl');
<?php
/* set parameters */
$parent = (!empty($parent) || $parent === '0');
$depth = isset($depth) ? (integer) $depth : 1;
$tpl = isset($tpl) ? $tpl : 'tpl';
$debug = (boolean) $modx->getOption('debug', $scriptProperties, false);
/* new query */
$criteria = $modx->newQuery('modResource');
/* retrieve only published, hidden, and isContainer*/
$criteria->where(array(
'published' => true,
'deleted' => false,
'hidemenu' => true,
'isfolder' => true,
));
/* get child ids of parent */
$categories = $modx->getChildIds($parent, $depth);
if(count($categories) > 0) {
$criteria->where(array(
'id:IN' => $categories,
)) or die($modx->log(modX::LOG_LEVEL_ERROR, '[getCategories] insert id Failed'));
}
$criteria->sortby('pagetitle','DESC');
/* get the resources as xPDOObjects */
$categories = $modx->getCollection('modResource',$criteria);
/* output */
$output = array();
foreach ($categories as $category) {
$phs = array_merge(
array('count' => $category->hasChildren()),
$category->toArray()
);
$output[] = $modx->getChunk('tpl',$phs);
}
$output = implode("\n",$output);
return $output;
?>`+id is not a valid integer and may not be passed to makeUrl()