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

    I’m trying to get my listing of items to be the same in the menu (in the modx user interface) and in the output.

    The menu is now set to sort by published date (the regular TV). Which works fine.

    However getting the Ditto output listing to do the same is not working.

    Listing by pub_date gives me error although all the items have one set (they should not need one hopefully later).


    THIS:
    [!Ditto? &parents=`2` &tpl=`news_item` &sortDir=`DESC` &sortBy=`pub_date` !]

    GIVES ME THIS ERROR:
    MODx encountered the following error while attempting to parse the requested resource:
    « PHP Parse Error »

    PHP error debug
    Error: array_multisort(): Argument #1 is expected to be an array or a sort flag
    Error type/ Nr.: Warning - 2
    File: /srv/www/htdocs/greyamsterdam.com/modx/assets/snippets/ditto/classes/ditto.class.inc.php(562) : eval()’d code
    Line: 1

    I’ve trying using published_on, published_by, published, orderBy - but either get error or it still lists by createdon.

    I guess I could make a new TV specially for publisheddate, but I dont want unnecessary dates, and besides that would likely mess up the sorting of the menu.

    Whats the best way to do this?

    Please help Im going nuts smiley

    Thanks

    tim


      • 4310
      • 2,310 Posts
      The later versions of Ditto use orderBy rather than sortDir & sortBy, so try :
      [!Ditto? &parents=`2` &tpl=`news_item` &orderBy=`pub_date DESC`!]
        • 30051
        • 14 Posts


        This works fine: [!Ditto? &parents=`2` &tpl=`news_item` &orderBy=`createdon DESC` !]

        But with pub_date

        [!Ditto? &parents=`2` &tpl=`news_item` &orderBy=`pub_date DESC` !]
        [!Ditto? &parents=`2` &tpl=`news_item` &orderBy=`publishedon DESC` !]

        I get this error:

        PHP error debug
        Error: array_multisort(): Argument #1 is expected to be an array or a sort flag
        Error type/ Nr.: Warning - 2
        File: /srv/www/htdocs/greyamsterdam.com/modx/assets/snippets/ditto/classes/ditto.class.inc.php(562) : eval()’d code


        with [!Ditto? &parents=`2` &tpl=`news_item` &orderBy=`published_on DESC` !]

        I get an output, but sorted on something other than published date, likely created on I guess

        Ideas?



        Line: 1
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          The field name is pub_date. As long as the documents actually have a publish date set, this should work.

          As far as I know, the Document Tree is sorted on the menu index by default, not the pub_date. In fact, it doesn’t even offer the option of sorting the Tree by pub_date in the Sort Tree dropdown.
            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
            • 30051
            • 14 Posts
            I’m afraid all items under parent 2 have a published date set manually. Still it doesnt work

            I dont want them to need to but really but it’s the only way...



            This with out the DESC

            [!Ditto? &parents=`2` &tpl=`news_item` &orderBy=`pub_date` !]

            gives me

            MODx encountered the following error while attempting to parse the requested resource:
            « Execution of a query to the database failed - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ’www, sc.id pub_date’ at line 4 »
            SQL: SELECT DISTINCT sc.alias,sc.publishedon,sc.pagetitle,sc.published,sc.id FROM `grey`.`grey_site_content` sc LEFT JOIN `grey`.`grey_document_groups` dg on dg.document = sc.id WHERE sc.id IN (6,37,38,40,55) AND sc.published=1 AND sc.deleted=0 AND (sc.privateweb=0) GROUP BY sc.id ORDER BY sc.id www, sc.id pub_date

            Looking at the SQL seems like it would work apart from the missing comma between sc.id and pub_date (or rather - whats sc.id doing there?)
              • 4310
              • 2,310 Posts
              ORDER BY sc.id www, sc.id pub_date
              Where is www coming from?
              Do you have the RTE on and it’s adding something?
              On Evo 1.0.2, I’ve just tested
              [!Ditto? &parents=`15` &tpl=`ditto_test` &dateSource=`pub_date` &orderBy=`pub_date DESC` !]
              and it works fine
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                That is definitely messed up. The sc.id is shorthand for site_content.id, i.e. the id field of the site_content table.

                Either put your parameters in an external config file, or put the whole Ditto snippet call in a chunk to get it out of the Rich Text editor.
                  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
                  • 30051
                  • 14 Posts
                  oh sorry the "www" as my mistake (I just wanted to see if doing orderby=www, date would in fact alter the SQL string cuz then I could have gone with a comma - but i posted wrongly in here)


                  whats an RTE sorry?


                  [!Ditto? &parents=`2` &tpl=`news_item` &orderBy=`pub_date DESC`!]

                  gives me no error but the sorting is off

                  Order of pub_date’s:
                  Oct 27, 2009
                  Mar 8, 2010
                  Feb 26, 2010

                  I dont get it:)


                    • 30051
                    • 14 Posts
                    "Either put your parameters in an external config file, or put the whole Ditto snippet call in a chunk to get it out of the Rich Text editor."

                    Sorry - how do I do this?


                    I thinking now I messed up the SQL when I edited something to make the menu sorting work.
                    Dont remember what I changed really though, however I saw no change on the output side.
                    Could these be connected?
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      If you look in assets/snippets/ditto you will see a configs directory. You can create a simple .php file (for example name it news.config.php) that defines the various parameters you would normally have in the Ditto call as plain PHP variables:
                      <?php
                      $parents = 2;
                      $tpl = 'news_item';
                      $orderBy = 'pub_date DESC';
                      ?>

                      You can even put the tpl itself here, instead specifying a chunk name.

                      Then your snippet call would look like this:
                      [!Ditto?config=`news`!]

                      Not much there for the Rich Text editor to mess up.

                      Alternately, just put your snippet call in a chunk, then where you want it to appear put the chunk tags {{name-of-chunk}}. Again, nothing here for the RTE to mess up.

                      There’s no reason why &orderBy=`pub_date DESC` shouldn’t work. This is presuming, of course, that you’re not using a really old version of Ditto.
                        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