We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36549
    • 572 Posts
    Hi,

    I have seen in another post(http://modxcms.com/forums/index.php?topic=47341.0) that displaying random content can be achieved with getResources.
    I want to display random quotes in a section of a page, in Evo i would have used the randomParagraph snippet.
    Could someone tell me how getResources RAND() would be used as i’m unable to find any examples?
    I would think i could make a container and add the quotes in individual resources amd assume it would be something along the lines of (i may be way off here though):
    [[!getResources?
    &parents=`6`
    &limit=`1`
    &sortby=`RAND()`
    ]]

    There is possibly a more efficient way to do this so any advice welcomed.

    Thanks

    j

      www.9thwave.co.uk
         WEB | DESIGN | PRINT
      • 22019
      • 390 Posts
      There are a couple of Extras that publish content that doesn’t need to be a resource (eg EZFAQ), or you could build a small custom table to do the job.

      I’ve done it as you outlined, with published resources in a hidden directory, remembering to exclude these from Google sitemaps as well.

      [[!getResources? &parents=`ID OF HIDDEN FOLDER` &sortby=`RAND()` &limit=`1` &tpl=`randomQuoteTpl`]]
        Writer > E-consultant > MODx developer || Salesforce || modx 2.x || PHP 5.2.13 || MySQL client 5.0.86
        • 36549
        • 572 Posts
        Hi,

        Thanks for your reply.
        This is still not generating any content.
        I have the following in a TV within a resource where ID6 is the container resource for the quotes:
        [[!getResources? &parents=`6` &sortby=`RAND()` &limit=`1` &tpl=`randomQuoteTpl`]]
        the randomQuoteTpl chunk is simply:
        <p>[[+content]]</p>

        What am i missing?

        Thanks j



          www.9thwave.co.uk
             WEB | DESIGN | PRINT
          • 22019
          • 390 Posts
          If getResources isn’t displaying any results:

          1. Remove the tpl parameter and run again. If it returns an array, then there’s a problem with your tpl (mispelt, or plain wrong). If there isn’t...
          2. Check there are published resources under the &parents container
          3. Check that the resources are not set to ’hide from menus’ (unless the showhidden parameter is overridden in the call)
          4. Check that the resource containing getResources call isn’t RichText (this can cause ampersands to appear as html entities (’& amp ;’ instead of &) - which causes the parameters not to fire). You can also get around this by putting your getResources call in a chunk.
          5. Check that the user you are previewing the call with has access to the resources you want to return (if using Resource groups and permissions).
            Writer > E-consultant > MODx developer || Salesforce || modx 2.x || PHP 5.2.13 || MySQL client 5.0.86
            • 29019 ☆ A M B ☆
            • 104 Posts
            Make sure you have &includeContent=`1` in your getResources call too.
              www.darkstardesign.com

              Are you in the Nashville area? Join us for our next MODX meetup!
              • 36549
              • 572 Posts
              Thank you for all your help, it is now working on all but one page even though the page uses the same template which is a mystery but not a huge issue.

              Thanks again.
                www.9thwave.co.uk
                   WEB | DESIGN | PRINT