We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37321
    • 4 Posts
    Anyone know if you can output Wayfinder results from Articles to be sorted by the &includeDocs param?

    I understand I would need to use the &sortBy param, but not sure best way to handle this. Here is my current call:

    [[Wayfinder? &ignoreHidden=`1` &startId=`4` &includeDocs=`7,18,15,17,10,16`]]


    The 4 references the Id of the Articles Container and the includeDocs param includes the Ids of the articles. I suppose I could sort by some custom TV value or something but would like to avoid that if possible.

    Thanks!
      • 42562
      • 1,145 Posts
      What do you mean by sorting? What criteria are we thinking of? Ordered according to ...?
        TinymceWrapper: Complete back/frontend content solution.
        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
        • 37321
        • 4 Posts
        Let me clarify:

        The order that I have in the includeDocs param is the order I would like output: 7,18,15,17,10,16.

        The ids are from a collection of Articles, so these are not just regular resources in a doc tree that I can rearrange and do a custom sortBy param. At least not as far as I am aware.

        Is there a way to hand-select ids and order them by how they are listed?
          • 3749
          • 24,544 Posts
          There's a default sortby, so I don't think you can do it that way.

          The only way I can think of is to set the menuindex field or a TV and set the sortby property to `menuindex` or the TV.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 37321
            • 4 Posts
            Quote from: BobRay at Aug 24, 2013, 03:58 PM
            There's a default sortby, so I don't think you can do it that way.

            The only way I can think of is to set the menuindex field or a TV and set the sortby property to `menuindex` or the TV.

            Since it is an Article, I don't believe there is an option to set the menuindex. I will probably just utilize a custom TV and sort by that.

            Thanks, Bob!
              • 3749
              • 24,544 Posts
              I don't think you can see the menuindex field when editing Articles, but I think you could in NewsPublisher and you definitely could in PhpMyAdmin, though that's not very convenient.


              Here's a trick you might try.

              Put this snippet tag above the Wayfinder tag in the template.

              [[!ArticlesMenuOrder? &docs=`7,18,15,17,10,16`]]


              Add these Wayfinder properties to the Wayfinder tag: &sortBy=`menuindex` &sortOrder=`ASC`

              Then, create a snippet called ArticlesMenuOrder with this code:

              <?php
              /* ArticlesMenuOrder snippet */
              
              $docs = explode(',', $scriptProperties['docs']);
              
              $i = 0;
              foreach ($docs as $doc) {
                 $modx->getObject('Article', $doc);
                 if ($doc) {
                     $doc->set('menuindex', $i);
                     $doc->save();
                     $i++;
                 }
              }
              



              This is a relatively slow solution -- you'll have to see if the page-load times are acceptable. If not, here's a much faster alternative:

              Remove the ArticlesMenuOrder tag from the template (but leave the properties in the Wayfinder tag). Put the ArticlesMenuOrder tag in the content of a separate Resource. When you want to set the order for a set of Articles, just edit the tag and preview the page. That will set the menuindex fields for those Articles and they should stay set until you change them.


              [ed. note: BobRay last edited this post 13 years, 1 month ago.]
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting