I extended Everett's snippet a little, to include the following:
- 4 levels
- using the ⌊ sign to indicate next level
- adding the id after the pagetitle
- option to exclude ID's on each level.
I'm not a php expert so this might be done in a more efficient way, but it works for me
I thought I'd post it here for others who might be interested.
<?php
/**
* Supports listing out the contents of a single folder that can contain pages or
* folders up to 2 levels deep only, e.g. if you have a folder of pages (one page
* for one "category") :
*
* Categories
* +--- SubCategory1
* | +--- EndCategory1
* | +--- EndCategory2
* |
* +--- SubCategory2
* +--- SubCategory3
*/
// Get top-level categories
$criteria = array();
$criteria['parent'] = (int) $parent;
$criteria['deleted'] = '0';
$criteria['published'] = '1';
$criteria['hidemenu'] = '1';
$query = $modx->newQuery('modResource', $criteria);
// id's that should not be included on root level
$query->where(array('id:NOT IN' => array(186,26,119)));
$resources = $modx->getCollection('modResource', $query);
$output = array();
$top_level_ids = array();
foreach ($resources as $r) {
// OUTPUT LEVEL 1
$output[] = $r->get('pagetitle') .' ('.$r->get('id').')=='.$r->get('id');
// Get sub-levels
if ($r->get('isfolder')) {
$criteria['parent'] = $r->get('id');
$query = $modx->newQuery('modResource', $criteria);
// id's that should not be included on this level
$query->where(array('id:NOT IN' => array(142,165)));
$sub_resources = $modx->getCollection('modResource', $query);
foreach ($sub_resources as $sr) {
// OUTPUT LEVEL 2
$output[] = ' ⌊ '.$sr->get('pagetitle').' ('.$sr->get('id').')=='.$sr->get('id');
if ($sr->get('isfolder')) {
$criteria['parent'] = $sr->get('id');
$query = $modx->newQuery('modResource', $criteria);
// id's that should not be included on this level
$query->where(array('id:NOT IN' => array(163)));
$sub_sub_resources = $modx->getCollection('modResource', $query);
foreach ($sub_sub_resources as $ssr) {
// OUTPUT LEVEL 3
$output[] = ' ⌊ '.$ssr->get('pagetitle').' ('.$ssr->get('id').')=='.$ssr->get('id');
if ($ssr->get('isfolder')) {
$criteria['parent'] = $ssr->get('id');
$query = $modx->newQuery('modResource', $criteria);
// id's that should not be included on this level
$query->where(array('id:NOT IN' => array(171)));
$sub_sub_sub_resources = $modx->getCollection('modResource', $query);
foreach ($sub_sub_sub_resources as $sssr) {
// OUTPUT LEVEL 4
$output[] = ' ⌊ '.$sssr->get('pagetitle').' ('.$sssr->get('id').')=='.$sssr->get('id');
}
}
}
}
}
}
}
return implode('||',$output);
EDIT: while this works great in the list, a selected item is shown as & nbsp ; ... etc. which is not so good. Probably the reason Everett used simple dashes!