Friday, March 7, 2003

Fun With Plugins!

one feature of MT that i absolutely cannot lose is the ability to have my index page sort from latest to earliest, but for archive pages to have their entries in chronological order. as with most blosxom things, there is no built in functionality for that, but with one of the 2.0 beta's, you can write a plugin that replaces the built in sort.

i suspect someone out there has written one that's nicer, but here's mine.

#!/usr/bin/perl -w

# Blosxom Plugin: reverse
# Author(s): Garrett Rooney
# Version: 0.0
# Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/

package reverse;

sub start {
1;
}

sub sort {
return sub {
my($files_ref) = @_;

if ($blosxom::path_info_yr eq ""
&& $blosxom::path_info_mn eq ""
&& $blosxom::path_info_dy eq "") {
return sort { $files_ref->{$b} <=> $files_ref->{$a} } keys %$files_ref;
} else {
return sort { $files_ref->{$a} <=> $files_ref->{$b} } keys %$files_ref;
}
};
}

1;

No comments:

Post a Comment