-
- 7 Posts
Hello Everyone,
For a long time I've been researching on how I can quotes change across the page whenever a visitor visits an individual page. However, this question becomes double fold because I do not know how I should store this and then regenerate these quotes. I need some help, because if they were images it would be easy to just create a image gallery and have them uploaded, however, with quotes it's just text files. Is there an add-on that will read and write a short text file to specific area on the template? Also, these quotes will need to be randomly generated. At this time the database for these quotes + authors is small, but is expected to get quite large over time. I'm looking for any suggestions. Thanks.
Joe
I would use MIGx, or if you expect to have a lot of quotes, MIGXdb (using a custom database table). Something like this tutorial, only just have a textarea field for the quote and a text field for the author, so your schema would be much simpler.
http://rtfm.modx.com/extras/revo/migxdb/migxdb.tutorials/migxdb.create-a-basic-gallery-management-from-scratch-with-migxdb
-
- 24,544 Posts
Lucky you.
This page at my site uses that exact example:
http://bobsguides.com/custom-db-tables.html.
Getting a random quote is fairly easy. This should do it (untested):
$criteria = $modx->newQuery('Quote'); // use your class name here
$criteria->sortby('RAND()'); //
$criteria->limit(1); //Limit the results to 1
$quote = $modx->getObject('Quote',$criteria); // use your class name here
if ($quote) {
$fields = $quote->toArray();
return $modx->getChunk('QuoteChunk', $fields);
} else {
return "Failed to get quote";
}
Just put placeholders for the quote fields in a chunk called "QuoteChunk" and you should be in business.