We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18397
    • 3,250 Posts
    The major limitation in sorting by a user defined date until this point has been that MODx does not store date TV’s in UNIXTIME (it stores them in MySQL Timestamps). I found a simple and clever workaround that maintains backawards compatibility. Just create a widget that takes whatever value in the database (can even be a text field), and turn it into a UNIXTIME stamp that Ditto can use to sort. You now have the ability to enter dates both in text format or using the date chooser. The UNIXTIME Widget has been included in MODx 0.9.5 and later. Then, just append &sortBy=`tvnameofyourtemplatevariable` to your Ditto call and you are done!
      • 33114
      • 518 Posts
      Thanks for your work Mark! But unfortunately this only make a UNIXTIME output for a tv, still Ditto isn’t sorting by it sad
      Look what I have:
      the call
      [!Ditto? &startID=`17` &sortBy=`tvdate` &sortDir=`ASC` &tpl=`ditto_works` &summarize=`5`!]


      output with data formatter widget:

      Веб-сайт компании «Венте» («Ватель-Фестен») (Tuesday 27, December 2005)
      Веб-сайт компании «Примавель» (Thursday 30, March 2006)
      Веб-сайт компании «Astelcom» (Wednesday 15, March 2006)
      Дизайн веб-сайта компании «FastHelix» (Monday 28, November 2005)

      and output with the unixtime widget:
      Веб-сайт компании «Венте» («Ватель-Фестен») (1135640114)
      Веб-сайт компании «Примавель» (1143671995)
      Веб-сайт компании «Astelcom» (1142379790)
      Дизайн веб-сайта компании «FastHelix» (1133134700)

      the order keeps the same - by createdon.
        http://modx.ru - российская поддержка MODx
        http://newscup.ru - экспериментальный проект
        http://yentsun.com - персональный сайт
        • 18397
        • 3,250 Posts
        And you are using Ditto 1.0.2 right?
          • 23948
          • 15 Posts
          i am using 1.02 and this doesn’t work for me either.

          instead of your approach, I hacked the date formatter to use the php date() function instead of strfrmtime or whatever it is. Using ’U’ as the parameter, so the end result is the same. when you output the TVs there are in unixtime.

          [[Ditto? &tpl=`EventsMoreEvents` &startID=`41` &truncLen=`30` &displayArchive=`0` &summarize=`10` &paginate=`1` &sortBy=`tvGGEShowDate1`]]


          that’s my ditto call. but sadly, no sorting.

            • 23948
            • 15 Posts
            hi,

            changing

            if ($advSort == $sortBy){
            	$ditto->customSort($resource, $advSort, $sortDir);
            }


            to

            	$ditto->customSort($resource, $advSort, $sortDir);
            


            gets it working! at this point I know enough about your code to really start breaking things. grin but not enough to find the real source of the bug. i do know however, that this code:
            $sortBy = isset($sortBy) ? $ditto->checkSort($sortBy, $dateFormatType, $mode) : "createdon";
                // get sortBy
            


            sets $sortBy to "id", when before this validation routine its the name of the template variable. is this right?

            thanks mark! i’m content with my ugly hack for now but I’d sure like to help you with the real solution.
              • 4419
              • 2 Posts
              Hi Mark
              I tried your solution but alas it still is ordered by ID, it returns a timestamp like this (1060235247) - I also tried protocol0’s hack - the debug mode had listed it as (sortBy): pub_date, when I set it to pub_date - but it didn’t actually follow the order properly.

              Has anyone else found a way of sorting the Ditto list or have I missed something

              I have missed something - I didn’t format the date correctly - I used the calendar module and it all worked fine!

              Thanks
              by
                • 19004
                • 33 Posts
                Hmm. Well, I haven’t tried any of the hacks above, but the reason for that is that (besides not knowing how to add a widget) shifting the date widget to a unix time means that I’ll be trading a sorting problem for a display problem. I need my dates displaying in a "November 08, 2006" format at the same time as sorting on that date.

                Is there a way to do this?
                  • 17717
                  • 433 Posts
                  I too would like to sort my news by publish date, I am not sure what a widget is in relation to modx, could you help us out here.

                  Thanks
                  Lee
                    http://www.blend.uk.com | Web Design by Blend
                    • 18397
                    • 3,250 Posts
                    @mediced

                    Use a snippet like DateFormat


                    @lw-d


                    A widget is used to format the output of a tv
                      • 7291
                      • 129 Posts
                      Good morning Modx users,

                      Modx-0.9.5, Ditto 2.0.0, Reflect 1.0.0

                      I have a weekly newsletter that gets sent out. The menu/page of Biz Flash looks like this with multiple ditto calls:

                      Biz Flash page (2)
                      [!Ditto? &startID=`3` &tpl=`DittoTemplate`!]
                      Apples (3)
                      News1 (6)
                      News2 (7)
                      [!Ditto? &startID=`4` &tpl=`DittoTemplate`!]
                      Oranges (4)
                      News1 (8 )
                      News2 (9)
                      [!Ditto? &startID=`5` &tpl=`DittoTemplate`!]
                      Bananas (5)
                      News1 (10)
                      News2 (11)
                      Etc….

                      The newsletter gets sent out every Friday so the goal is to keep the news from Friday-Friday showing on this page. Stories from the previous week and before would be stored in archives by reflect.

                      I’m wondering if there’s a solution that can be found by using the date filter, TVs, &sortby=published_on in last 7 days, or something along those lines…

                      Anyone have a suggestion? Imagine there are a few people that may have come across this situation.

                      Have a good day, and thanks in advance

                      Derek
                        [center]-- smiley --[/center]
                        [center]New View Media - Custom Website Design[/center]
                        [center]Custom Website Design & Marketing = Strategic Business![/center]