We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44649
    • 68 Posts
    I've found this script
    <?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'] = '0';
     
     
    $query = $modx->newQuery('modResource', $criteria);
     
    $resources = $modx->getCollection('modResource', $query);
     
    $output = array();
     
    $top_level_ids = array();
    foreach ($resources as $r) {
        $output[] = $r->get('pagetitle') .'=='.$r->get('id');
        // Get sub-levels
        if ($r->get('isfolder')) {
            $criteria['parent'] = $r->get('id');
            $query = $modx->newQuery('modResource', $criteria);
            $sub_resources = $modx->getCollection('modResource', $query);
            foreach ($sub_resources as $sr) {
                $output[] = ' ---- '.$sr->get('pagetitle').'=='.$sr->get('id');   
            }
        }
    }
     
    return implode('||',$output);


    On the following page on the forums:
    https://forums.modx.com/thread/81563/multi-select-listbox-of-child-resources?page=2

    However it only allows showing the children within a specified document, would it be possible to modify it to use the entire site tree down to 2 levels?

    Thanks