We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Here’s a snippet somewhat like the NewsListing snippet, only it shows a given number of random items taken from a given folder.

    Right now it only shows the introtext (summary) but it won’t take much to make it show other fields as does NewsListing.

    It has three arguments, startDoc, numItems, and tpl.
      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
      • 6726
      • 7,075 Posts
      We sure needed this kind of snippet, a common plugin in other CMS...

      With the stardDoc and tpl parameter we have MODx flexibility on top of randomizer capability smiley
      I sure will use this in the future, thanks Susan !
        .: COO - Commerce Guys - Community Driven Innovation :.


        MODx est l'outil id
      • I’m sure it will grow a bit as people will want to show other parts of the document, such as the title or longtitle as a link, but for now it works great for simple blocks of content to be displayed randomly.
          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
          • 12561
          • 7 Posts
          This is exactly what I was after. I’ve talked about it here:
          http://modxcms.com/forums/index.php/topic,1042.msg20780.html#msg20780

          Exactly how do I call this snippet? Is it possible to add the following information:


          • Page Title, which links to document
          • A template variable

          I’m new to MODx, so any help is appreciated smiley
          • I was being lazy when I quickly threw this together for a specific request.

            To add something, add another placeholder to the template, such as

            <div class="randItem">
                <h3 class="randLink"><a href="[~[+id+]~]">[+title+]</a></h3>
                <p>[+summary+]</p>
            </div>
            


            then add these lines after line 39:

            $items .= str_replace('[+id+]',$resource[$item]['id'],$tpl);
            $items .= str_replace('[+title+]',$resource[$item]['pagetitle'],$tpl);


            It needs to be rewritten to allow for an arbitrary number of placeholders, at least.

              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