article a day random text

Xilb51X

Junior Member
Joined
Mar 25, 2009
Messages
158
Reaction score
38
i have a site and it has 5 pages (adsense) anyways is there a way i can take the main content and use php to pull random articles that are page specific and appear every time a visitor loads the page?
so say 1 page is apples, i need the script to pull all articles about apples and another page is oranges i need the code to pull a article about oranges but i would like to just have one php code on each page and then have it pull a the articles from a folder that i make instead of editing the page every time? hopefully this makes sense. thanks for the time. im also using Dreamweaver.
 
Sure. put the ready-made articles in a directory for each page, in the php just grab a list of all of the file names, put into an array, select a random one and voila. I'm not going to write it for you, but here's what im talking about in a sense:

Code:
<?
$myDir = opendir("./oranges/");

while($file = readdir($myDir)) {
   $fileList[] = $file;
}

closedir($myDir);

$articleCount = count($fileList);

$randNumber = (rand()%$articleCount);
$randArticle = $fileList[$randNumber];

// now open the article and display it

$fh = file_get_contents($randArticle);

echo $fh;
?>

Or at least that's what I thought you were looking for.
 
Back
Top