The 10 most recent updates on a website
Posted: Sat Jun 25, 2005 12:34 pm
First post in this forum, I'm rather new to Php but find it interesting. I also hope you understand my English since it's not my language.
I have a website and would like to list the ten recently updated pages in a table with 'title' of the page and date changed and with a link to that page.
Like:
Links ( 2005-06-19 22:57 )
-------------
A guy on another forum suggested a code... and it works pretty well
except that the order isn't according to the date when the pages is updated. Instead I get a list of the most recent updated pages according to alphabetical order. I guess something is wrong, probably the 'rsort' command because it list according to filenames, but I have tried to change it but to no success.
The guy who helped me with the script knows PHP much better than me but couldn't see what was wrong in the code.
As I said I'm not good in PHP but maybe someone with better knowledge in PHP understands what's missing in the code?
I have a website and would like to list the ten recently updated pages in a table with 'title' of the page and date changed and with a link to that page.
Like:
Links ( 2005-06-19 22:57 )
-------------
A guy on another forum suggested a code... and it works pretty well
except that the order isn't according to the date when the pages is updated. Instead I get a list of the most recent updated pages according to alphabetical order. I guess something is wrong, probably the 'rsort' command because it list according to filenames, but I have tried to change it but to no success.
The guy who helped me with the script knows PHP much better than me but couldn't see what was wrong in the code.
As I said I'm not good in PHP but maybe someone with better knowledge in PHP understands what's missing in the code?
Code: Select all
<?php
$dir = "./";
// searching of filetypes
$filetypes = Array( "php","htm" );
// the title
// [pagename] => [name]
$titles = Array( "index.php"=>"startsidan", "heja.php"=>"hejsidan" );
$foundtype = "";
if ( is_dir($dir) ) {
if ( $dh = opendir($dir) ) {
$filenames = Array();
while ( ($file = readdir($dh) ) != false) {
$foundtype = explode(".",$file);
if ( ($file != "." && $file != ".." && $file[0] != '.') && array_key_exists($file, $titles)) {
$filenames[] = $file;
}
}
closedir($dh);
}
}
rsort($filenames);
$maxnum = 10;
$count = count( $filenames );
if ( $count > 10 )
$count = $maxnum;
if ( $count > 0 ) {
echo "$count recent updated pages:<p>";
for ($i = 0; $i < $count; $i++) {
// namn som visas om inte filen finns med i listan
$tmp = "Untitled";
if ( array_key_exists($filenames[$i], $titles) ) {
$tmp = $titles[$filenames[$i]];
}
echo ($i+1).". <a href=\"$filenames[$i]\">".$tmp."</a> ( ".date("Y-m-d H:i:s", filemtime($filenames[$i]))." )<br>";
}
echo "</p>";
}
else {
echo "<p>Didn't found any webpages.</p>";
}
?>