pyrosarco Posted November 13, 2007 Share Posted November 13, 2007 I want to make a folder filled with blog posts by date. Each file will be like 20071113.php and 20071031.php basically the date they were written 2007, 10 for october, and 31 for the day. But each will be notated like that so that the number is always increasing. How would I make a php include function as to take the last ten highest numbers and add it to a page? (Basically the last ten posts by date) and How would I include more than one post per date? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted November 13, 2007 Share Posted November 13, 2007 Well, very simply, something like this might suffice: <?php $files = array(); $path_to_folder = 'path/to/your/folder/of/blogs/';//where is this folder? foreach(glob($path_to_folder.'*.php') as $file){//cycle through each .php file in that folder - i assume it ONLY contains blogs? $files[] = $file; } rsort($files);//sort our files foreach($files as $file){ include($file); echo '<br />'; } ?> Given the consistant naming format, sorting by the file name will work fine to sort them by date/ I'm assuming you do want to include the files, since you said they are .php files - rather than plain text files which you'll want to grab with file_get_contents() and echo. Personally, i think you're far better off using a database for storing your blogs though. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.