We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7455
    • 2,204 Posts
    This is originaly a snippet called RandomPageLink made by Jared.

    I adapted the snippet so that it displays the introtext instead of the pagetitle.
    That way you can use it as a Random Quote Snippet
    I made a folder containing Testemonies from satisfied costumers and grabbed a quote from that document and put that in the introtext field (Summary).

    I added the snippet to my template so that it displayes a nice quote on every page the quote is linked to the page it comes from so by klicking the quote you will go to that page.

    Would be nice if it could be edited so we could select a TV. way more options are availible that way, but until that time this works fine for quotes.

    All the credit must go to Jared, I am just a hacker.

    Dimmy
      follow me on twitter: @dimmy01
      • 4273
      • 356 Posts
      how do we tag this in the html like this ? [randomquotelink] what do we use to pull the quotes ?
        SMF Bookmark Mod - check it out
        http://mods.simplemachines.org/index.php?mod=350
        • 7455
        • 2,204 Posts
        you tag it like any other snippet

        [[RandomQuoteLink]] or [!RandomQuoteLink!]

        A comma separated string list of parent IDs like:
        ’85,3,6’
        Can be set in snippet call with RPL_parents:
        [[RandomQuoteLink?RPL_parents=85,3,6]]

        then the snippet will grab the introtext from a random page inside one of those folders and display’s it including a link to that page

        hope this helps

        Dimmy
          follow me on twitter: @dimmy01
          • 4273
          • 356 Posts
          is there anyway to leave the quote as just text and not link to a page ?

          I’ll say one thing about this snippet, it sure is random he he i can never tell when the next quote is going to load,
          is this something we can configure ? i tried clearing the browser but that didn’t do it,
            SMF Bookmark Mod - check it out
            http://mods.simplemachines.org/index.php?mod=350
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            I can’t remember if I’ve released this yet or not, but it’s an extremely simple snippet for grabbing the content of random documents from a given folder. Would be easy enough to modify it to give another option of which field to return (title, longtitle, introtext, content, etc)
            // snippet ShowRandom
            // display content from random documents
            // sottwell 01-2006
            // arguments:
            //    &startDoc - ID of folder to select items from
            //    &numItems - number of random items to display
            //    &tpl = chunk name for item display template
            
            $startDoc = isset($startDoc) ? $startDoc : $modx->documentIdentifier;
            $numItems = isset($numItems) ? $numItems : 1;
            $tpl = isset($tpl) ? $modx->getChunk($tpl) : '
                <div class="randItem">
                  [+content+]
                </div>
            ';
            $resource = $modx->getActiveChildren($startDoc, 'createdon', 'DESC', $fields='id, pagetitle, description, introtext, content, createdon, createdby, hidemenu');
            $limit = count($resource);
            if(!function_exists(randArray)) {
              function randArray($size, $min, $max) {
                 if ($size > $max)
                     $size = $max;
                 $v = array();
                 while ( count($v) < $size ) {
                     do {
                         $n = rand( $min, $max );
                     } while ( array_search($n, $v) !== false);
                         $v[] = $n;
                 }
                 return $v;
              }
            }
            $list = randArray($numItems,0,$limit-1);
            $items = '';
            foreach($list as $item) {
                $items .= str_replace('[+content+]',$resource[$item]['content'],$tpl);
            }
            return $items;
            
              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
              • 3232
              • 380 Posts
              Does this prevent items from being called in more then once?
                • 4224
                • 11 Posts
                Nice Snippet. I would like to have 2 more peices of information to show ( id, introtext ). I have the [+longtitle+] working fine but when I try to add these other 2 items it doesn’t work.
                How can I adjust the code to have this other information availible.

                Thanks for the help.

                Jeff
                  • 15988
                  • 10 Posts
                  Great script smiley
                  I would like to call the snippet two times and get different on each of the results. (I’ve tried calling the script without cache, but it still gives me the same output).