On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • this snippet doesn't have a sortby - option.

    If you need that, use getResources or pdoResources.
    Also migxLoopCollection, bundled with MIGX would do it, or rowboat.

    for publishedon you will need

    [[+publishedon]]


    [[*publishedon]]

    does allways get the value from the current resource.
      -------------------------------

      you can buy me a beer, if you like MIGX

      http://webcmsolutions.de/migx.html

      Thanks!
    • It depends on whether they are all immediate children (e.g., no grandchildren).

      If there are no grandchildren, this will be significantly faster:

      $docId = $modx->resource->get('id');
      $tpl = $modx->getOption('tpl',$scriptProperties,'');
      if (!$tpl) { 
          return 'No template given.'; 
      }
      
      $c = $modx->newQuery('modResource');
      $c->where(array('parent' => $docId));
      $c->sortby('publishedon', 'DESC');
      
      $docs = $modx->getCollection('modResource', $c);
      
      $output = '<h2>[[*pagetitle]]</h2><ul>'; 
      
      foreach ($docs as $doc) {
          $fields = $doc->toArray();
          $output .= $modx->getChunk($tpl, $fields);
      }
      
      $output .= '</ul>';
      
      return $output;


      If there are grandchildren, you can do it like this:

      $c = $modx->newQuery('modResource');
      $c->sortby('publishedon', 'DESC');
      $docs = $modx->resource->getMany('Children', $c);
      

        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
      • Thank you so much, @BobRay. It worked for me – and I've added some code so only published and not-deleted childs are active. Here's the code:

        $docId = $modx->resource->get('id');
        $tpl = $modx->getOption('tpl',$scriptProperties,'');
        if (!$tpl) { 
            return 'No template given.'; 
        }
         
        $c = $modx->newQuery('modResource');
        $c->where(array('parent' => $docId, 'deleted' => 0, 'published' => 1));
        $c->sortby('publishedon', 'ASC');
         
        $docs = $modx->getCollection('modResource', $c);
         
        $output = '<h2>[[*pagetitle]]</h2><ul>'; 
         
        foreach ($docs as $doc) {
            $fields = $doc->toArray();
            $output .= $modx->getChunk($tpl, $fields);
        }
         
        $output .= '</ul>';
         
        return $output;
        • Looks great. I'm glad I could help. smiley
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting