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
    You can sortBy publishedon and then use a filter that compares the publishedon value to an @EVAL that returns the time - 7 days.
    Your filter would look like &filter=`publishedon,@EVAL return strtotime("-1 week");,6`
      • 7291
      • 129 Posts
      Thanks for the advice! I have spent a couple of days trying to figure this out and it’s getting messy...

      (updated to Ditto 2.0.1)
      First I created the following TV:
      name: [*dittoSort*]
      input type: Date
      Input Option Values: @EVAL return strtotime("-1 week");,6`
      widget: unixtime
      sortorder: 0
      connected it to the necessary templates

      and on the template page have the following call:
      [!Ditto? &parents=`2` &display=`all` &tpl=`DittoTemplate` &dateSource=`pub_date` &sortBy=`pub_date` &depth=`2` &hideFolders=`1` &filter=`publishedon,@EVAL return strtotime("-1 week");,6`!]

      [!Reflect? &parents=`2` &tpl=`DittoTemplate` &dateSource=`pub_date` &display=`all` &depth=`2` &sortBy=`pub_date` &getDocuments=`1`!]

      and the TV selector at the bottom of the page says dittoSort: (not set)

      So I have tried many different options and this is what I have at the moment. If leave out the ditto call: &filter=`publishedon,@EVAL return strtotime("-1 week");,6` the news gets sorted properly. If I put in this ditto call it returns only 5 news stories from what seems random dates. Reflect is also not working but I’m focussed on getting ditto to work first.

      Running around in circles... how can I get Ditto to display news from the last seven days and the articles older than 7 days get stored in archive by reflect?

      Really would like to get something working. Have a nice day

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

        I am sorting on a TV date already; and I’d like to create a calendar with DittoCal based on that date too.

        is Ditto’s json output aware of the dateSource thing?
        it seems to output the same exact values for the "date": part inside each one of the json ’entries’, with and without the $datesource parameter (and related orderBy) in the Ditto call.



        CIAO
          ----------------------------------------------------------
          http://www.linkedin.com/in/lucapost/
          http://www.twitter.com/lukwe/
          ----------------------------------------------------------
          • 18397
          • 3,250 Posts
          JSON does not currently handle dateSource. This feature is currently planned. You can use a custom JSON template in the meantime.
            • 1747
            • 24 Posts
            Quote from: Mark at Aug 08, 2006, 12:46 AM

            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!
            Hello,
            I want to sort Ditto output by a user defined date (TV with unixtime widget), but if user forgot to set up this TV, I want to use createdon value instead.
            Can you help me?
              • 18397
              • 3,250 Posts
              You would need to write an extender for that. Take a look at the example extender included in the Ditto distribution for more information.
                • 30516
                • 5 Posts
                Hi, I have an events page where my events are showing in order of page id ascending, no matter what I try to use in Ditto. I tried orderby published date, and manipulated those, but it’s still just going by order of page id. (By page id, I mean the number shown in brackets after the page title, in the document tree - I think that’s ’id’?)

                I had tried:

                [[Ditto? &startID=`4` &summarize=`4` &total=`20` &tpl=`event` &sortBy=`pub_date` &sortDir=`DESC` &paginate=`1` &alwaysshow=`1`]]
                Showing [+start+] to [+stop+] of [+total+] events

                ..and then I followed the MODx tutorial at

                http://ditto.modxcms.com/tutorials/sort-by-a-date-tv.html

                I created a tv called ’event_date’, set it up as per tutorial, checked I could see it in my template variables list, made sure it was applied to template ’events’ (ref’d in SQL below) but get’unknown column’ msg for event_date:

                « MODx Parse Error »
                MODx encountered the following error while attempting to parse the requested resource:
                « Execution of a query to the database failed - Unknown column ’sc.event_date’ in ’order clause’ »
                SQL: SELECT DISTINCT sc.* FROM `db196473060`.modx_site_content sc LEFT JOIN `db196473060`.modx_document_groups dg on dg.document = sc.id WHERE (sc.id IN (30,36,25,24,23,37,21,34,49,48,15,50,46,47) AND sc.published=1 AND sc.deleted=0 ) AND (sc.privateweb=0) GROUP BY sc.id ORDER BY sc.event_date DESC

                I then tried sorting by id descending:


                [[Ditto? &startID=`4` &summarize=`4` &total=`20` &tpl=`event` &sortBy=`id` &sortDir = `DESC` &paginate=`1` &alwaysshow=`1`]]
                Showing [+start+] to [+stop+] of [+total+] events

                ..but it still lists them in ascending id.

                Please help!
                Thanks,
                Tracy
                • TVs go in their own tables in the database; they aren’t part of the site_content table.

                  Your sorting problem is most likely the result of a bug in the version of MySQL you are using.
                    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
                    • 30516
                    • 5 Posts
                    Hi Susan, thanks very much for the quick response.

                    "TVs go in their own tables in the database; they aren’t part of the site_content table" - sorry for extra explanation required - I’m new to MODx/MySQL; what’s the significance of this? I found the tv table in mySQL/phpAdmin - do I need to add the tv to the site_content table as well?

                    "Your sorting problem is most likely the result of a bug in the version of MySQL you are using" - again, this is probably a stupid question, but what description should I use for the bug then, when querying the MySQL bugs documentation? Don’t understand the problem enough to ask them!

                    All I need is some way to order them manually, whether that’s by manipulating publishing dates or whatever. I just don’t have any control over it at the minute.

                    Thanks very much for your time & help,
                    Tracy

                    • http://bugs.mysql.com/bug.php?id=32202

                      The query is trying to sort by sc.event_date, but event_date is not in the sc (site_content) table. You need to specify the name of the tv to sort by in the Ditto call, as explained in the tutorial.

                      &sortBy=`event_date` &dateSource=`event_date`

                      But there’s no guarantees, because of the MySQL bug.
                        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