Help - Search - Members - Calendar
Full Version: Random Quotes
Movable Type Community Forum > Additional Resources > Tips and Tricks
jasontromm
There's been a lot of talk about adding random quotes to MT pages.  I like the idea and I'm starting to write code that will do just that.  It's just a PHP fragment right now, but I plan to rewrite in Perl and make it an MT Plugin (as soon as I figure out how.)

To use, you need MT 2.6 or above, a MySQL database and PHP of course.  You need some way to create new tables in your database (I use phpMyAdmin)

Short instructions:

1. Unpack the files in this zip file
2. Copy db.inc.default to db.inc
3. Change $hostName, $databaseName, $username, and $password to match your database values.
4. Upload db.inc and index.php to a new directory on your server.
5. You also need to create a table as defined in mt_quotes.sql
6. Insert rows into your new table (I've included a few quotes from America's Founding Fathers in founding_fathers.sql, you can run that script on your database to get a start.)

Please contact me with any questions or comments.

The code is licensed under the current Creative Commons Attribution-NonCommercial-ShareAlike license.
Deane
Jason:

This is great, but the RandomLine plugin is an awfully handy way to do it.  You can grab a random line from a template module, even, so to update it, you never have to leave the Moveable Type interface.

My module is called "Quotes," and the code is:

CODE
<$MTRandomLine module="Quotes"$>

You can also specify a number of lines to pull, whether you want duplicates, etc.  It works beautifully.

Deane
david_collantes
QUOTE
Jason:

This is great, but the RandomLine plugin is an awfully handy way to do it.  You can grab a random line from a template module, even, so to update it, you never have to leave the Moveable Type interface.

My module is called "Quotes," and the code is:

CODE
<$MTRandomLine module="Quotes"$>

You can also specify a number of lines to pull, whether you want duplicates, etc.  It works beautifully.

Deane

The randomline only refreshes when there is a rebuild, no good. Jason approach is better for random text every time the page is accessed.
kenvallot
On my site, I use the following within a "quotes.html" template.  I have around 40 quotes to choose from, but my problem is that I wish I knew why the random-ness (?) of the script picks the same few quotes and shows them over and over again.  I  eventually get to see them all when I refresh enough times, but I end up seeing the same handful of quotes ten times or more before I get through them all.

CODE
<script LANGUAGE="Javascript"><!--

function text() {
};

text = new text();
number = 0;

text[number++] = "\"A bore is a man who, when you ask him how he is, tells you.\"  Bert Taylor"

// add a whole bunch more quotes here...

increment = Math.floor(Math.random() * number);

document.write(text[increment]);

//--></SCRIPT>


Let the record show that I got this idea and general script from cgiscript.net
kenvallot
oops.  trying to delete this post, as it was completely unnecessary!
Deane
Oh-h-h-h-h, I see what you're doing: refreshing the quote every time, not just on a rebuild.  My mistake. Sorry.

Deane
kenvallot
That's what I like about this particular php include; it will refresh every time the page is visited.  No worries about rebuilding for a new quote.
bmk
(I think some of the confusion is coming from talkin like this is something new when it's the same thing we already have been doing for random.  not that I don't think it's great...)
jasontromm
This is different because it reads from a database table (mt_quotes)  The table has fields for things like author, blog_id, date_created, etc.  These fields will allow all kinds of options for selecting which quotes get displayed.  It will even allow a "Quote of the Day" instead of just a "Random Quote." I'm also considering writing a PHP form to update the tables.
bmk
It might work well to use a new blog to enter the quotes in, that will update the tables automatically and you can run the queries against the mt_tables then...   wink.gif
jasontromm
I considered using a new blog, but threw out the idea because I couldn't customize it the way I wanted. I want the quotes to be available on every blog on my site. (Yes, I know there's MTOtherBlog)
bmk
smile.gif smile.gif I'm surely not trying to discourage you, I think you have a nifty idea.  smile.gif  If you're querying the db, it doesn't matter which blog it's in. You can select from one, or two, or whichever you want.
FilSchiesty
I currently use a script that seems to meet the requirements of you guys.
It uses mysql to house a db of quotes and a php script to query the db for a quote.
Works nice and has a easy to use web-interface to add/modify/delete etc...

Check it out here...
http://node777.net/tquotes.php
jasontromm
Thanks, I'm gonna go check it out right now! tongue.gif
FilSchiesty
Let me know how it goes Jason.
biggrin.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.