We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 35384
    • 26 Posts
    I think this is the place to ask this question as it seems to be what I am trying t achieve.

    I have a list of upcoming events/shows and on my home page I want to show 4 shows in a banner and then 3 events/shows randomly picked in a side bar. If you refresh the page i would like theses 3 randomly picked shows to change but at the moment they don't and they stay the same.

    For the banner I have:
    <
    [[getResources?
    &parents=`2`
    &tpl=`BannerSlide`
    &includeTVs=`1`
    &processTVs=`1`
    &limit=`4`
    &instance=`1`
    ]]
    >

    and for the sidebar I have:
    <
    [[getResources?
    &parents=`2`
    &limit=`3`
    &tpl=`WhatsOnListItem`
    &includeTVs=`1`
    &processTVs=`1`
    &sortby=`RAND()`
    ]]
    >

    How do I get it to load 3 more randomly picked events/shows when the page is refreshed ?
    • You need to call getResources uncached so [[!get...
        Patrick | Server Wrangler
        About Me: Website | TweetsMODX Hosting
        • 35384
        • 26 Posts
        Thanks you so much, this has given me a headache for days and the solution was so simple. Much appreciated
        • Quote from: macboy25 at Nov 18, 2012, 07:47 AM
          Thanks you so much, this has given me a headache for days and the solution was so simple. Much appreciated

          Glad I could help smiley
            Patrick | Server Wrangler
            About Me: Website | TweetsMODX Hosting
          • Quote from: MrFussyfont at Sep 30, 2010, 02:21 AM
            Thought I'd share something useful I discovered with getResources. Not sure if this should be posted here or in the getResources forum; too bad you can't cross-post or use tags...

            The site I'm working on has a bunch of testimonials or quotes from happy customers. I wanted the ability to show a random one in the sidebar. You can do something like this with the RandomChunk add-on, but it requires a comma-separated list of chunks. Instead I put each quote in a separate resource and found a way to select one at random for the sidebar and also be able to list them all on a 'Testimonials' page.

            Since the sortby param is passed to the SQL you can use the MySQL 'RAND()' function:
            [[!getResources? &parents=`27` &limit=`1` &tpl=`testimonial` &includeContent=`1` &sortby=`RAND()`]]

            The above will select a random resource that is a child of resource id 27. To list all the resources in random order, just change the limit to zero.

            Gotta hand it to you, though this is an older post, it's EXACTLY what we needed for one of our clients. Two thumbs up!
              Woodlands Ad Agency
              Our blog should NOT be read by anyone....EVER http://woodlandsadagency.com/blog/
              ...Don't say we didn't warn you.
              • 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
              • For all of you NON-programmers (like me) here is a jump-start to make this work. (Assuming you are wanting to make a simple random quotes). This mini-tutorial is under the assumption that you already have getResources installed.

                1. First make a chunk and give the chunk a title of 'randomQuotes'
                2. Next put this code inside your chunk:

                <div class="quotes">[[+content]]</div>


                3. Make a folder in your resources where you want your quotes or testimonials to be placed
                4. Make note of the ID that is assigned to this folder
                5. Select 'hide from menus' and 'published' (although you don't have to hide from menus if you don't want)
                6. Now in your template (or a separate chunk), the code below is what you need to make everything work

                [[!getResources? 
                    &parents=`25`
                    &limit=`1`
                    &tpl=`randomQuotes`
                    &includeContent=`1` 
                    &showHidden=`1`
                    &depth=`10`
                    &sortby=`RAND()`
                ]]
                


                Keep in mind &parents=`25` <--This number will be the ID assigned to the folder containing your quotes
                Also note &showHidden=`1` is optional if you are not hiding your quotes from the menus.

                7. Test it to make sure everything worked and that it's pulling 1 random quote when you refresh your page
                8. Last step - VERY IMPORTANT! - Donate to MODX if this worked for you. (no I do not work for MODX)


                Hope this helps!
                [ed. note: adagency last edited this post 10 years, 11 months ago.]
                  Woodlands Ad Agency
                  Our blog should NOT be read by anyone....EVER http://woodlandsadagency.com/blog/
                  ...Don't say we didn't warn you.
                  • 42560
                  • 49 Posts
                  Quote from: MrFussyfont at Sep 29, 2010, 09:21 PM
                  Thought I'd share something useful I discovered with getResources. Not sure if this should be posted here or in the getResources forum; too bad you can't cross-post or use tags...

                  The site I'm working on has a bunch of testimonials or quotes from happy customers. I wanted the ability to show a random one in the sidebar. You can do something like this with the RandomChunk add-on, but it requires a comma-separated list of chunks. Instead I put each quote in a separate resource and found a way to select one at random for the sidebar and also be able to list them all on a 'Testimonials' page.

                  Since the sortby param is passed to the SQL you can use the MySQL 'RAND()' function:
                  [[!getResources? &parents=`27` &limit=`1` &tpl=`testimonial` &includeContent=`1` &sortby=`RAND()`]]

                  The above will select a random resource that is a child of resource id 27. To list all the resources in random order, just change the limit to zero.

                  This is a nice tip, and a cool idea when you dont want to change the front side of the page, but let the code generate it everytime(in some portions of the site)... but not offense here, my reasoning:

                  What about google bots reading your site? i mean, having random content showing everytime your user enters, lets say, the same page, is not a cause for a possible penalty?.

                  i have a large websites, with thousands of page(more than 10k) and editors are not willing to change the site every day, not even every week. so i decided to do that random thing in most of my menus, that &sortby=`RAND()` code was so simple to put in every getresources, but then i remembered that MR. Google comes to my site(dunno how often a day or days) and read the content(and structure) of the site.

                  Or users come to my site, lets say, bryan comes to my home page, scan the entire page, and probably he likes a article(located in my right side menu), and for some reason he clicks the refresh button, and ¡boom! the article is gonna because the random code was there. Bad news for bryan because he wont be able to read it again, or recomended it to another person since the article is no longer there.

                  i would use it with caution in production sites, not pretty sure if google will consider this a Spam or something else indetriment of my site.

                  Thats my opinion.