Page 1 of 1

randomyze some content

Posted: Sat Feb 04, 2006 7:01 am
by kermit
make a user-defined tag, call it randomyze, then insert into your template or content area: {randomyze}

Code: Select all

// insert random block from a text file. it is inserted as-is,
// so be careful. :)
//
// place a ~ between blocks in file being randomyzed, like this:
//
//   <h2>one</h2>
//   <p>some text</p>
//   ~
//   <h2>two</h2>
//   <p>some other text</p>
//   ~
//   <h2>three</h2>
//   <p>third time is the charm</p>
//
// without first and last lines below, would be suitable for non
// content applications, e.g. randomyzing stylesheets.

echo "<div id=\"randomyze\">";
$c_myze = join ('', file ('./uploads/randomyze_data.txt'));
$s_myze = split("~",$c_myze);

$n_myze = rand(0,(count($s_myze)-1));
echo $s_myze[$n_myze];
echo "</div>";
obviously very basic. no checks or balances. you have been warned.
one of those 'works for me and YMMV' things. :)


sample data file attached.


[attachment deleted by admin]

Re: randomyze some content

Posted: Sat Mar 04, 2006 1:04 pm
by kermit
yea, i could be used for ad rotation, but there are better things out there for that. i've also got another one that just pulls a random image from a specified directory. great for randomizing header images.

i kinda like how this one just dumps code in, as then you could randomize a flash element, some text, images or even a script all in the same spot on the page. it could also be used to randomize stylesheets, although i haven't quite got drunk enough to slap that on a production site (could you imagine everything getting rearranged on every page view. hehe)

and you're spot on for the layout of the data file. see the sample if you haven't yet.

Re: randomyze some content

Posted: Sat Mar 04, 2006 2:17 pm
by cyberman
Tygger2512 wrote: Presumably this could be used for Ad rotation?
For this you can use banners module from CMSms Forge  ;) ...

Re: randomyze some content

Posted: Sun Mar 04, 2007 9:15 pm
by carasmo
Can this be used for random divs containing photos, text, and links, like side bar stuff? If so, can you send the link to the sample text file, it was deleted by the admin.

Re: randomyze some content

Posted: Sun Mar 04, 2007 9:21 pm
by kermit
carasmo wrote: Can this be used for random divs containing photos, text, and links, like side bar stuff? If so, can you send the link to the sample text file, it was deleted by the admin.
read the comments in the code. it's spelled out there....

content
~
content
~
content

and so forth... "~" is the separator, so don't use it in any "content".

there are some additions to the forge since i first posted this.. check out:
http://dev.cmsmadesimple.org/search/?ty ... rch=Search