Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sorting menu by Published Date
#5
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

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.
My Github Repos: Github
Website: DigiMute
Reply


Messages In This Thread
Sorting menu by Published Date - by rab - 2009-10-02, 02:38:08
Sorting menu by Published Date - by rab - 2009-10-02, 07:32:26
Sorting menu by Published Date - by n00dles101 - 2009-10-02, 07:49:14
Sorting menu by Published Date - by rab - 2009-10-02, 08:02:20
Sorting menu by Published Date - by n00dles101 - 2009-10-02, 08:31:58
Sorting menu by Published Date - by rab - 2009-10-02, 08:43:18



Users browsing this thread: 1 Guest(s)