Log in

View Full Version : "Live" links (directories)



rpflorence
02-03-2008, 02:38 AM
So I'm new to PHP (and programming). I've created a flat file family blog that is automatically organized by directories each time I submit a new entry, in other words, each entry creates a new directory based on the date/time.

I'd like to place a link at the bottom to the next entry, and the previous entry.

So the directories might look like this:

2008_01_28_12_24/
2008_01_31_05_14/
2008_02_01_09_54/
2008_02_03_21_03/

Inside each is an index.php. I'd like to have a link that creates itself to the next, and previous directories on each page.

Could I read all the directory names into an array, sort them, and then put the current directory into a variable, and then somehow compare the current directory to the array and then place links to the one above and the one below the current?

Thanks! :D

Medyman
02-03-2008, 04:48 AM
Are you using WordPress or something of the like? Because most of those systems have this kind of functionality built in.

djr33
02-03-2008, 11:18 PM
Certainly possible. Try visiting php.net and looking at a set of:

$dir = opendir('.');
while ($f = readdir($dir)) {
if ($f=='.'||$f=='..') { continue; } //skip this loop because you don't want the current directory or parent directory
//do something with $f which is the name of the next file/directory* in the directory, in a loop
//* you can skip directories by changing the if above to if (strpos($f,'.')==0)
}
closedir($dir);

http://www.php.net/manual/en/function.opendir.php
Lots of info there and on neighboring pages (see the navigation menu on the left, and all of the posts below each page).

If you still need help, go ahead and ask, but that should give you a great idea about the general use of these functions.

rpflorence
02-04-2008, 04:12 AM
Thanks for the link, I'd already poked around a bit at php.net but this looks more promising than where I was before.

To Medyman, this is my very first, homegrown PHP 'app' I wrote from scratch o.O