We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38142
    • 91 Posts
    In a homemade snippet to get resources, the following line does not work:

    $criteria->sortby('menuindex','ASC');


    It is ignored and resources are ordered by ID instead of menuindex. sortby('pagetitle','ASC')works a treat, but sortby('menuindex','ASC') doesn't.

    Is there a way to get a homemade snippet to order resources according to menuindex?

    This question has been answered by Bruno17. See the first response.

    • discuss.answer
      • 4172
      • 5,888 Posts
      This should work. Are you sure, your resources have different menuindex - values?
      Does sorting by menuindex work with getResources or pdoResources?
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 38142
        • 91 Posts
        Bruno, there is a blog in a different part of the site where the post resources are controlled by getResources using this call:

        [[!getResources? &parents=`25` &limit=`80` &depth=`1` &showHidden=`0` &tpl=`blogpost` &includeContent=`1` &includeTVs=`1` &processTVs=`1` &tvPrefix=`` &sortby=`menuindex` &sortdir=`ASC`]]


        That works fine. So menuindex is working there but not when I try to call it from my snippet with the above line of code on another list of child resources.
          • 38142
          • 91 Posts
          Bruno17, I take my hat off to you. You are right. Although the blog post child resources have a menuindex, the other child resources that my homemade snippet is trying to order apparently do not. How is that possible? Do you know how I can somehow "switch" the menuindex on for those child resources?

          In the past when I had another problem with sortby menuindex not working, I went to Settings and changed change context_tree_sortby from "rank" (which it was by default) to "key". I have already done that for this site.
            • 38142
            • 91 Posts
            Okay. Sorted. Dragging and dropping the child resources a few times seems to have jigged the system into operation and now the menuindex figures have all (bar one) moved away from 0. The code above now works as you said it should.

            Thank you.