I am using the following scritp to create a display of Folders and the files linked in them. Looks like this:
2004
- August
- March
- September
2007
- April
- October
- January
2005
- June
- Janurary
- November
There are two problems that having to do with sorting. I need to sort the Folders(years) from current to oldest (2008, 2007, 2006, 2005, etc.) Then the files(months) in monthly order. Would that be chronological? Anyway any help would be appriciated. Here is the code:
Code: Select all
<?php
// Remove the ext
function RemoveExtension($strName)
{
$ext = strrchr($strName, '.');
if($ext !== false)
{
$strName = substr($strName, 0, -strlen($ext));
}
return $strName;
}
// List folders and files
function ListFolder($path)
{
//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");
//Leave only the lastest folder name
$dirname = end(explode("/", $path));
//display the target folder.
echo ("<h2>$dirname</h2>\n");
echo "<ul>\n";
while (false !== ($file = readdir($dir_handle)))
{
if($file!="." && $file!="..")
{
if (is_dir($path."/".$file))
{
//Display a list of sub folders.
ListFolder($path."/".$file);
}
else
{
//Display a list of files.
echo "<li><a href='";
bloginfo('template_url');
echo "/Newsletters/$dirname/$file' target='_blank'>" . RemoveExtension($file) . "</a></li>";
}
}
}
echo "</ul>\n";
//closing the directory
closedir($dir_handle);
}
// Get the base folder
$base_folder = getcwd();
$ourDir = $base_folder . "/wp-content/themes/TA_custom/Newsletters/";
ListFolder($ourDir);
?>