We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44234
    • 219 Posts
    Quote from: lancipoos at Dec 09, 2013, 10:31 AM
    I'm trying to use GetResources to display a random selection of only two of the four most recent posts. So any two of the most recent four posts. Using &limit=`2` works well to display purely the two most recent posts. Introducing RAND is fine to display all post randomly. So wanting to limit the RAND to only the most recent 4 posts. Tried using &where but failed. Any help appreciated.

    I think the sortby parameter will be applied to all resources before the limit parameter is used. Because if you don't know how to sort, how do you know which resources fall within the limit? With that in mind I don't think you will be able to randomise the 4 most recently published resources as you either sortby publishedon or rand().

    The only other ways I can think of is to manually set the menuindex for your resources and use use that to filter the output. Or use a tv to select the resources you want to include. Neither are very practical.

    What's the reason it has to be the 4 most recent posts? It would be a lot easier to sort randomly, limit output at 2, where published in the last day/week/whatever.
      Find me on Twitter, GitHub or Google+
      • 44922
      • 131 Posts
      Hi David. Thanks for your post. You are right - if I just sort randomly and limit to the last month this has more or less the same effect. Great suggestion. Why didn't I think of that?

      For those of you struggler with a similar issue, David has written a getDate package available in the package management and has posted a bunch of examples with sample code on how this can be used here: http://rtfm.modx.com/extras/revo/getdate.

      Nice work, thanks again.
        • 44234
        • 219 Posts
        No problem, glad you found the snippet useful
          Find me on Twitter, GitHub or Google+
          • 44922
          • 131 Posts
          On another note, has anyone any experience with displaying GetResourses in scrolling vertical tickertape? We have a client wanting to have their news items scroll automatically, so a couple of posts are always visible, but on a rotating vertical scroll. Can't find a Modx package for this and the various JQuery / Javascript code attemples we have made we can't seem to get to work. I was wondering whether the problem was that the <li> tags for each news item in GetResources is called from the ArticlesLatestPostTpl, rather than being coded in the page. Any help appreciated.
            • 30912
            • 463 Posts
            getResources is just an output snippit, you need to make sure the ticker works first if its a ticker that works on <li>'s then your chunk needs to reflect that

            take this for example: http://richhollis.github.io/vticker/

            your html would be (assuming that its coming from articles)

            
            <div id="example">
              <ul>
            [[getResources? 
            &parents=`8` //articles parent
            &limit=`5` //number of items
            &tpl=`tickerTpl` //ticker template
            &showHidden=`1` //articles are hidden so this overrides that
            ]]
              </ul>
            </div>
            
            


            tickerTpl

            <li>[[+pagetitle]] - [[+longtitle]]</li>
            


            Not tested but should work right out the box.

            Good Luck - but you should've started a new thread wink