randomyze some content

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
User avatar
kermit
Power Poster
Power Poster
Posts: 693
Joined: Thu Jan 26, 2006 11:46 am

randomyze some content

Post 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]
eternity (n); 1. infinite time, 2. a seemingly long or endless time, 3. the length of time it takes a frozen pizza to cook when you're starving.
4,930,000,000 (n); 1. a very large number, 2. the approximate world population in 1986 when Microsoft Corp issued its IPO. 3. Microsoft's net profit (USD) for the quarter (3 months) ending 31 March 2007.
CMSMS migration and setup services | Hosting with CMSMS installed and ready to go | PM me for Info
User avatar
kermit
Power Poster
Power Poster
Posts: 693
Joined: Thu Jan 26, 2006 11:46 am

Re: randomyze some content

Post 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.
eternity (n); 1. infinite time, 2. a seemingly long or endless time, 3. the length of time it takes a frozen pizza to cook when you're starving.
4,930,000,000 (n); 1. a very large number, 2. the approximate world population in 1986 when Microsoft Corp issued its IPO. 3. Microsoft's net profit (USD) for the quarter (3 months) ending 31 March 2007.
CMSMS migration and setup services | Hosting with CMSMS installed and ready to go | PM me for Info
cyberman

Re: randomyze some content

Post by cyberman »

Tygger2512 wrote: Presumably this could be used for Ad rotation?
For this you can use banners module from CMSms Forge  ;) ...
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm

Re: randomyze some content

Post 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.
User avatar
kermit
Power Poster
Power Poster
Posts: 693
Joined: Thu Jan 26, 2006 11:46 am

Re: randomyze some content

Post 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
eternity (n); 1. infinite time, 2. a seemingly long or endless time, 3. the length of time it takes a frozen pizza to cook when you're starving.
4,930,000,000 (n); 1. a very large number, 2. the approximate world population in 1986 when Microsoft Corp issued its IPO. 3. Microsoft's net profit (USD) for the quarter (3 months) ending 31 March 2007.
CMSMS migration and setup services | Hosting with CMSMS installed and ready to go | PM me for Info
Post Reply

Return to “Tips and Tricks”