We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5187
    • 14 Posts
    Hello all, have a quick question as it relates to ordering documents when pulling certain docs into a page.

    i have the following code:

    [[Ditto? &documents=`153,155,186,184` &display=`100` `&dateFormat=`%B %e, %Y` &sortBy=`title DESC` &tpl=`PartnersBox`]]


    works just the way i want, however i want to order by the "&documents=" bit just as they are listed there "153,155,186,184" where 153 is at the top and 184 is the last one.

    is there a way to do this with the "&orderby" code or is there another way? right now i have it set obviously by "title"

    i have done a few searches in here however haven’t found what iam looking for
      • 849
      • 19 Posts
      It sounds really easy but me either didn’t found any built in parameters that would keep the order as is.
      Did you tried to use the menuindex? or is it something you don’t want to change?

      If so, maybe you can try:
      It would sound very inconvenient, but how about making a template variable for them?
      for example:

      • Make A TV named ditto_index
      • Make it available to all of the templates of docs # 153,155,186,184
      • Set the doc #153’s ditto_index to 1
      • Set the doc #155’s ditto_index to 2
      • Set the doc #186’s ditto_index to 3
      • Set the doc #184’s ditto_index to 4
      • use &sortBy=`ditto_index`&sortDir=`ASC` parameter
      • If it works, try to remove the access of all the other templates, to prevent confusion ? (not so sure, but modx doesn’t delete them right? just don’t delete the template variable ditto_index)
        • 4172
        • 5,888 Posts
        or create an new ditto-extender with this code:

        <?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;
        
        ?>
        
        
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 849
          • 19 Posts
          Interesting, how to call the snippet with that extender + use it for sorting? or is it done by the extender parameter only?
            • 4172
            • 5,888 Posts
            create a new extender in folder assets/snippets/ditto/extenders

            name it e.g. sortByDocuments.extender.inc.php

            call Ditto with [!Ditto? ................&extenders=`sortByDocuments`..........!]

            and Ditto sorts the documents as they come in &documents
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 5187
              • 14 Posts
              thanks for your help worked out perfectly!