Jump to content

php include files from a folder


pyrosarco

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.