By Sebastiaan de Jonge, published on Monday, January 25, 2010 at 17:52

If you're not aware of the capabilities of TypoScript, you would start looking in the repository for something usable. I immediately remember using something similar for getting a content element from a different page, and displaying it. Combining this with a COA_INT, to prevent caching of the element, I was able to do this in under 5 minutes with only 15 lines of TypoScript code (including marker assignment).
lib.quotes = COA_INT
lib.quotes {
    10 = CONTENT
            pidInList = 91
            max = 1
            orderBy = RAND()
        renderObj = TEXT
        renderObj.field = header
It works rather simple:
  • We create a COA_INT to prevent the element from being cached
  • We select 1 element from the tt_content table, from our storage page (SysFolder, 91)
  • We order our selection by RAND() (MySQL) in order to make the content random.
  • We just add the header to be rendered and displayed.

That's it! The downside is that RAND() doesn't work in MSSQL as it works in MySQL. For this we can use NEWID() instead of RAND(). I'm pretty sure something similar is also possible for other database systems, haven't looked it up or tested it though.