We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8161
    • 39 Posts
    Hi,

    Here is the issue:

    I have four TV variables for different pages. Every page can have only one of the following variables:

    - free
    - silver
    - gold
    - platinum

    I’m using ditto call to take the content for all pages:

    [!Ditto? &parents=`4, 40, 75, 110` &tpl=`Client` &dateSource=`createdon` &orderBy=`DESC`!]

    As you can see I sortby with DESC. Is it possible to sortby with the TV variables - free, silver, gold, platinum.

    Pages which have variable platinum will load first, second will be gold, third will be silver and last will be free.

    The content looks like a list, so I’m trying to sort them platinum will be first on the top of the page and free will be last on the bottom of the page.

    Any Ideas smiley
      • 7231
      • 4,205 Posts
      Yes. You need to add the tv to the orderBy clause: &orderBy=`tvname DESC` or you can use the old style parameters &sortBy=`tvname` &sortDir=`DESC`

      Pages which have variable platinum will load first, second will be gold, third will be silver and last will be free.
      Not really since the ordering needs to follow an alphabetical order. So in this example it will be Silver, Platinum, Gold, Free.
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don't know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 8161
        • 39 Posts
        Thanks very much,

        Actually it didn’t work as I would like.

        The problem is that I need something like sort and another sort for this. So let say I have couple items and every one of them have some variable silver, platinum, gold, free.

        What I would like is first sort of all items and see which type of variable we have and then sort by createdon so newest will be on top. For example:

        1. Items with Platinum variable order by date newest on top
        2. Items with Gold variable order by date newest on top
        3. Items with Silver variable order by date newest on top
        4. Items with Free variable order by date newest on top

        Is that make any sense?
          • 20413
          • 2,877 Posts
            @hawproductions | http://mrhaw.com/

            Infograph: MODX Advanced Install in 7 steps:
            http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

            Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
            http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
            • 8161
            • 39 Posts
            Quote from: mrhaw at Feb 25, 2009, 03:43 PM

            This can be done by tagging.
            http://ditto.modxcms.com/files/assets/snippets/ditto/extenders/tagging-extender-inc-php.html

            Thanks, but I’m not sure that I could do this with tagging.

            I just need to two sort options, first sort by Platinum, Gold, Silver, Free and second to sort already sorted items by createdon or DESC or ASC.

            And all this have to be in only one ditto call.

            Any ideas?
              • 16278
              • 928 Posts
              And all this have to be in only one ditto call.
              Is there a particular reason for it being in one call? Four calls, one for each category, would make it so much simpler.
                • 8161
                • 39 Posts
                Quote from: Keith at Feb 26, 2009, 03:14 AM

                And all this have to be in only one ditto call.
                Is there a particular reason for it being in one call? Four calls, one for each category, would make it so much simpler.


                Yes, it will be simpler, but when you have 100 items from five different categories the sort will work 5 times for them and the result will be:

                sorted results 1, sorted results 2 and etc. but when I have it one call I will be able to sort 2 times all of them. Another thing is that I don’t thing it’s possible to make ditto call for ditto call ... smiley

                What I’m trying to do is something like:

                function which sortby(sortby (tvname asc), createdon) .. .something like function in function as I said before, 2 sorts, 1-st by tvname ASC, and second will sort this items by createdon or opposite I don’t thing it’s make any difference.
                  • 4172
                  • 5,888 Posts
                  what you can try is this:
                  create a snippet ’RunDitto’

                  <?php
                  //[!RunDitto? &parents=`4,40,75,110` &categories=`platinum,gold,silver,free` !]
                  
                  $categories=(isset($categories))?explode(',',$categories):array();
                  $output='';
                  foreach ($categories as $categorie){
                  $params=array();
                  $params['parents']=$parents;	
                  $params['tpl']='Client';	
                  $params['dateSource']='createdon';	
                  $params['orderBy']='DESC';	
                  $params['filter']='your_category_tv_name,'.$categorie.',1';	
                  $output.= $modx->runSnippet('Ditto',$params);	
                  }
                  
                  return $output;
                  ?>


                  call ist with:
                  [!RunDitto? &parents=`4,40,75,110` &categories=`platinum,gold,silver,free` !]
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 8161
                    • 39 Posts
                    Hm this produce the strange PHP error:

                    Fatal error: Function name must be a string in manager/includes/document.parser.class.inc.php(769) : eval()’d code on line 3

                    I copy and paste the same code, just change the &parents id ? Any ideas smiley
                      • 20413
                      • 2,877 Posts
                      With the request extender added to &extender you can have one ditto call and sort it by links next to it that generates urls.
                      http://ditto.modxcms.com/extenders/request.html

                      If using Friendly Url you would go like this:
                      <a href="[~[*id*]~]?ditto_sortBy=platinum&ditto_sortDir=ASC">sort by Platinum</a>

                      ?
                        @hawproductions | http://mrhaw.com/

                        Infograph: MODX Advanced Install in 7 steps:
                        http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                        Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                        http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower