A snippet-rotator for people using The Article System
23rd January 2006
If you’re using the Article System, this piece of code might come in handy for you. In the first manual i downloaded for it, it said they would show a way to include the article-snippets on the index-page, but that never happened, so I managed to hack something up myself. Notice: this isn’t pretty, but it seems to do the trick
It should reside in the same directory as your snip_*.html-files, and a smart thing would be to rename your index-files to .shtml and put <[REMOVETHIS]!--#include virtual "randomsnippet.php" --> where you want the snippet to appear. Please put a nicely formatted paragraph-wrapper or something around that statement or it will look like shite!
—-< randomsnippet.php >—-
function getRandomFile($prefix)
{
$dir = opendir(’.');
while (($myfile = readdir($dir)) !==false)
{
if ($myfile != ‘.’ && $myfile != ‘..’ && is_file($myfile) && $myfile != ‘resource.frk’)
{
if(ereg(”^$prefix”, $myfile))
$files[] = $myfile;
}
}
closedir($dir);
srand ((float) microtime() * 10000000);
$file = array_rand($files);
return $files[$file];
}
$display = getRandomFile(”snip_”);
include($display);
?>
—-< randomsnippet.php >—-
That’s it. Enjoy. I’m not charging you for it
January 29th, 2006 at 17:34
[…] http://blog.free-info-central.com/2006/01/23/a-snippet-rotator-for-people-using-the-article-system/ […]