Help - Search - Members - Calendar
Full Version: Sort Categories by Date Modified?
Movable Type Community Forum > Using Movable Type > Entries and Archives
californiafox
I created a photoblog using Movable type, and wanted to have my main category index page sorted by which category was updated most recenetly. Unfortunately with the standard MT templates and tags, it sorts by Alphabetical only.... Anybody got any possible solutions?

To See what I'm talking about,check out the page
JM11195
I'm not sure this will work in your case...

Define a custom category sorting method in main index template:
CODE
<MTSubCategories sort_method="MT::Sort::ByCatRecent">
    ...
</MTSubCategories>


Then create a file named "Sort.pm" under the directory lib/MT/:
CODE
package MT::Sort;

use MT::Category;
use MT::Entry;
use MT::Placement;
use strict;

sub ByCatRecent ($$) {

   my ($a, $b) = @_;

   my ($a_entry) = MT::Entry->load( { blog_id => $a->blog_id }, {
       'join' => [ 'MT::Placement', 'entry_id', { category_id => $a->id } ],
       'sort' => 'created_on', direction => 'descend', limit => 1 });

   my ($b_entry) = MT::Entry->load( { blog_id => $b->blog_id }, {
       'join' => [ 'MT::Placement', 'entry_id', { category_id => $b->id } ],
       'sort' => 'created_on', direction => 'descend', limit => 1 });

   my $a_date = $a_entry ? $a_entry->created_on : 0;
   my $b_date = $b_entry ? $b_entry->created_on : 0;

   $b_date cmp $a_date;
}

1;

__END__


Rebuild indexes.
SeannyBoy
MTCollate would be able to do this - can be used to sort your entries any way you could ever want them, a great plugin!
-sean
WaywardPuppy.com
californiafox
I tried both solutions to no avail. I am using a category index page to show the page - Any other suggestions?
SeannyBoy
Umm... dont know about php since I dont use it but MTCollate really will (or at least can) do what you are looking.
What is the code you are using now?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.