Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-06-22 18:30:41

WhiteDog
Member
From: Maine
Registered: 2005-09-07
Posts: 174

Request for Random Quote plug-in

I spent some time searching for a random quote plug-in but could not find one. So I thought perhaps someone here could develop one.

I found this PHP script by Steve Dawson

<?php
## The name of the .txt file which hold the rotating info (currently random.txt)
$filename = “random.txt”;
$file = file($filename);

srand((double)microtime()*1000000); while ($RandomRotator == “”) { $RandomRotator = ereg_replace(“\n”,”“,$file[rand(0,count($file))]); }

## This prints the banner, quotes or random text, or whatever is in the random.txt file print “$RandomRotator”;
?>

this does what I am looking for but I’d love it if you could update to it with news articles and have as a plug-in.

Thanks to any one who reads this.


Grrr RRR nnndth grrr Skeek!

Offline

#2 2007-06-22 18:40:28

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Request for Random Quote plug-in

There is a plugin: dru_random_text that I used to use to do exactly that, but it’s old and I don’t know if it still works in 4.0.4. But you can do the same thing easily with <txp:article_custom sort="rand()" />.

Offline

#3 2007-06-22 18:51:21

reid
Member
From: Atlanta, Ga.
Registered: 2004-04-04
Posts: 224
Website

Re: Request for Random Quote plug-in

Els wrote:

There is a plugin: dru_random_text that I used to use to do exactly that, but it’s old and I don’t know if it still works in 4.0.4.

It’s still working for me in 4.0.4.


TextPattern user since 04/04/04

Offline

#4 2007-06-22 19:28:46

WhiteDog
Member
From: Maine
Registered: 2005-09-07
Posts: 174

Re: Request for Random Quote plug-in

thank you very much :D


Grrr RRR nnndth grrr Skeek!

Offline

#5 2007-06-22 19:36:28

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Request for Random Quote plug-in

For large numbers of rows/entries/articles, sort="rand()" or the SQL equivalent ORDER BY RAND() will be slow, but there are ways to get the same result much faster, using 2 queries: see the last comment by Colin Guthrie on this page

For dru_random_text, that would mean changing:

$sql    = "select $column from $table order by rand() limit 1";

into something like this (not tested):

$sql = "select $column from $table limit ".floor(mt_rand(0,getThing("select $column from $table")-1)).",1";

Last edited by ruud (2007-06-22 19:39:34)

Offline

#6 2007-06-23 16:40:59

truist
Plugin Author
From: Ohio, USA
Registered: 2004-11-09
Posts: 257
Website

Re: Request for Random Quote plug-in

I show random quotes on my site (at the bottom) by posting all the quotes as articles in a special ‘quotes’ section, and then using this:

<txp:article_custom section="quotes" form="quote_footer" limit="1" sortby="rand()" />

Last edited by truist (2008-07-03 11:40:48)

Offline

#7 2007-11-04 13:54:45

jameslomax
Member
From: UK
Registered: 2005-05-09
Posts: 448
Website

Re: Request for Random Quote plug-in

Quite old this.
Does anyone know if it’s working in 4.05?

Offline

#8 2007-11-04 16:24:33

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Request for Random Quote plug-in

If it’s working in 4.0.4, then it should work fine in 4.0.5

Offline

Board footer

Powered by FluxBB