I have a bunch of files in my ‘news’ folder and would like to have another page (archive page) that lists them by title (with the title linked) with the newest title listed first.
I did find the following php code that lists specific file titles in a directory, however not sure what to add to sort and make the title linkable.
[code=php]///////////////function my_strip///////////
function my_strip($start,$end,$total){
$total = stristr($total,$start);
$f2 = stristr($total,$end);
return substr($total,strlen($start),-strlen($f2));
}
/////////////////////End of function my_strip ///
///////////// Reading of file content////
$i=0;
$path=”../news/”;// Right your path of the file
$handle=opendir($path);
while (($file_name = readdir($handle))!==false) {
if(stristr($file_name,”.php”)){
$url=$path.$file_name;
$contents=””;
$fd = fopen ($url, “r”); // opening the file in read mode
while($buffer = fread ($fd,1024)){
$contents .=$buffer;
}
/////// End of reading file content ////////
//////// We will start with collecting title part ///////
$t=my_strip(“<title>”,”</title>”,$contents);
echo $t;
echo “<br>”;
$i=$i+1;
}
}
echo $i;
This one lists all the files (and are clickable):
[code=php] if ($handle = opendir(‘.’)) {
while (false !== ($file = readdir($handle)))
{
if ($file != “.” && $file != “..”)
{
$thelist .= ‘<a href=”/news/’.$file.'”>’.$file.'</a>’;
}
}
closedir($handle);
}
Any way to combine the two and sort by modified (newest first)?
Thanks.