We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7327
    • 195 Posts
    I think I’ve seen this before while starting out in Evo but I can’t figure out where I’ve seen it. Basically, if I had a homepage that had several child docs in it, if I go to the homepage directly, it’ll automatically redirect me to the latest child doc I entered. Does anyone know if this feature is indeed supported in either MODx Evo or Revo?

    Cheers,
    Les
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      There’s the FirstChildRedirect snippet, which redirects to the first child according to the menuindex values. That could be modified to get the latest child by using the resource IDs of the children instead:
      $docid = (isset($docid))? $docid: $modx->documentIdentifier;
      
      $children= $modx->getActiveChildren($docid, 'menuindex', 'ASC');
      if (!$children === false) {
          $firstChild= $children[0];
          $firstChildUrl= $modx->makeUrl($firstChild['id']);
      } else {
          $firstChildUrl= $modx->makeUrl($modx->config['site_start']);
      }
      return $modx->sendRedirect($firstChildUrl);
      
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 7327
        • 195 Posts
        Hi Susan,

        Is the code above ready for that? Or do I have to change ’menuindex’ to something else? I’m looking at:

        http://wiki.modxcms.com/index.php/API:getAllChildren

        and the $sort argument only says ’menuindex’.

        Cheers,
        Les
          • 3749
          • 24,544 Posts
          I believe you could also use this if you don’t want to mess with the menuindex settings:

          $children= $modx->getActiveChildren($docid, 'createdon', 'ASC', 'id,pagetitle,createdon,description,parent,alias,menutitle,class_key,context_key');
          


          You can remove any fields you don’t need from the last argument.


            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
            • 7327
            • 195 Posts
            Hi Bob,

            Thanks for the input, too. I’ll give this a try when it’s implementation time. The values - id,pagetitle,createdon,description,parent,alias,menutitle,class_key,context_key - are these table fields?

            Cheers,
            Les
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              class_key and context_key sound like Revo things; but yes, those are all fields for the site_content table.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 3749
                • 24,544 Posts
                Quote from: sottwell at Dec 02, 2010, 02:07 AM

                class_key and context_key sound like Revo things; but yes, those are all fields for the site_content table.

                Susan is right (as always) about class_key and context_key. You might have to remove those for it to work in Evolution.

                The defaults in Evolution for that argument are: ’id, pagetitle, description, parent, alias, menutitle’

                I don’t think any of them are required except the one you’re sorting by.
                  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
                  • 7327
                  • 195 Posts
                  All right, and I just put this snippet call in the parent doc whose latest child I want the system to jump to?
                    • 3749
                    • 24,544 Posts
                    Quote from: diatomin at Dec 03, 2010, 01:21 AM

                    All right, and I just put this snippet call in the parent doc whose latest child I want the system to jump to?

                    That’s right.
                      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