We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2396
    • 101 Posts
    Hi, can anyone help me out with this (hopefully) simple one? I’m using modx version 1.0.2.

    I’d like to sort selected documents that I have specified using the &documents parameter, but they must be output in the order they are listed. I just can’t find the right orderBy value.

    [!Ditto? &tpl=`officeTplNoLink` &parents=`7` &orderBy=`pagetitle ASC` &documents=`40,46,47,35,36,37,44,41,43,49,48,50,54,53`!]


    Or can anyone point me to a list of Ditto parameter values (not just the parameters themselves?)

    Thanks in advance.
      • 17883
      • 1,039 Posts
      Create an extender in assets/snippets/ditto/extenders/ with name customsort.extender.inc.php and the following content:

      <?php
      
      if (!function_exists('customsort'))
      {
      function customsort($a, $b)
      {
      $pos_a=array_search($a['id'],$GLOBALS['documents']);
      $pos_b=array_search($b['id'],$GLOBALS['documents']);
      
      if ($pos_a == $pos_b)
      {
      return 0;
      }
      return ($pos_a < $pos_b)?-1:1;
      }
      }
      
      $GLOBALS['documents']=explode(',',$documents);
      $orderBy["custom"][] = array ("id", "customsort");
      $ditto->advSort = true;
      
      ?>


      Call Ditto like this:

      [!Ditto? &tpl=`officeTplNoLink` &parents=`7` &extenders=`customsort` &documents=`40,46,47,35,36,37,44,41,43,49,48,50,54,53`!]
        • 2396
        • 101 Posts
        That’s awesome, it works perfectly – thanks!
          • 10449
          • 956 Posts
          Found this old thread when looking for the exact same thing. Thanks, that extender works a treat!
            • 28729
            • 43 Posts
            Brilliant smiley Thanks for this too... just used it and it works perfectly!
              • 33238
              • 388 Posts
              AMAZING mate, thank you very much!!! grin grin grin grin
                --
                ysanmiguel.com
                • 38557
                • 4 Posts
                Thanks! Great extender! )
                  • 7527
                  • 437 Posts
                  Hi, just to tag onto this thread. I am trying to get an orderBy call that will order documents by their title. For instance if their title holds a word the same as the current page, they are at the front of the results (basically I am trying to do like a related articles type thing!). I know with Ajax you have a &rank parameter, any ideas how to achieve a similar thing with ditto?
                    www.PawsForWildlife.co.uk
                    www.Borntobrick.co.uk
                    • 7527
                    • 437 Posts
                    Hi, just to tag onto this thread. I am trying to get an orderBy call that will order documents by their title. For instance if their title holds a word the same as the current page, they are at the front of the results (basically I am trying to do like a related articles type thing!). I know with Ajax you have a &rank parameter, any ideas how to achieve a similar thing with ditto?
                      www.PawsForWildlife.co.uk
                      www.Borntobrick.co.uk