We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38175
    • 48 Posts
    I have a couple of getResources questions. First, is it possible for getResources to select random child resources. For example out of 30 child resources, can getResources randomly choose 10 of them?

    Second question. When getResources gets resources, does it index them, i.e. resource #1, resource #2, etc. I ask because, via php, I want to test each resource as it is gathered and test whether its index is even or odd. If its index is even, do THIS if its index is odd, do THAT.

    Thanks

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

    • discuss.answer
      • 27708 MODX Staff
      • 2,502 Posts
      Quote from: scottmccullough at Nov 15, 2012, 06:51 PM
      I have a couple of getResources questions. First, is it possible for getResources to select random child resources. For example out of 30 child resources, can getResources randomly choose 10 of them?
      As far as fetching resoures you can &sortby=`RAND` and &limit=`10` but I am not sure how it fetches the results if it would fetch the first 10 and then sort them randomly.
      Quote from: scottmccullough at Nov 15, 2012, 06:51 PM

      Second question. When getResources gets resources, does it index them, i.e. resource #1, resource #2, etc. I ask because, via php, I want to test each resource as it is gathered and test whether its index is even or odd. If its index is even, do THIS if its index is odd, do THAT.

      Thanks
      getResources does index the items. You can set the index start integer using the &idx property. Additionally, there are already templates available for &tpl, &tplOdd, &tplFirst, &tplLast and tpl_N.

      You can find all this and more properties on the getResources Doc Page: http://rtfm.modx.com/display/ADDON/getResources

      All the best,

      Jay
        Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
        • 38175
        • 48 Posts
        Thanks, Jay. This is just what I was looking for.
          • 9102 ☆ A M B ☆
          • 318 Posts
          I'm pretty sure that sorting comes before limiting - it would have to, because if you don't know how to sort, how do you know which resources fall within the limit? So I expect this will do exactly what you want.