2009-10-02, 08:31:58
This is the way I did it for sorting Blog entries on my site.
my guess is you've taken the original menu code and changed it so your extracting the pubdate like so
change this to the following to convert the date/time to unixtime format, this make it easier
to sort on.
change the sort line to
add the following function to your code somewhere
use date() function to convert the unixtime format back into human readable.
hope it helps....
Mike.
my guess is you've taken the original menu code and changed it so your extracting the pubdate like so
Code:
$pagesArray[$count]['pubdate']=$data->pubDate;
change this to the following to convert the date/time to unixtime format, this make it easier
to sort on.
Code:
$pagesArray[$count]['pubdate']=strtotime($data->pubDate);
change the sort line to
Code:
$pagesSorted = sort2d($pagesArray,'pubdate','desc');
add the following function to your code somewhere
Code:
function sort2d ($array, $index, $order='asc', $natsort=FALSE, $case_sensitive=FALSE)
{
if(is_array($array) && count($array)>0)
{
foreach(array_keys($array) as $key)
$temp[$key]=$array[$key][$index];
if(!$natsort)
($order=='asc')? asort($temp) : arsort($temp);
else
{
($case_sensitive)? natsort($temp) : natcasesort($temp);
if($order!='asc')
$temp=array_reverse($temp,TRUE);
}
foreach(array_keys($temp) as $key)
(is_numeric($key))? $sorted[]=$array[$key] : $sorted[$key]=$array[$key];
return $sorted;
}
return $array;
}
use date() function to convert the unixtime format back into human readable.
Code:
echo date('M d Y, g:i:s',$page['pubdate']);
hope it helps....
Mike.