Category Sorting

Date
2005-03-30 (Wed)
Category
MovableType

MovableType でカテゴリの順番をかえてくれと、クライアントからリクエストがあったので、ちょっと調べてみた。

まずは本家 MovableType のドキュメント…(Six Apart の情報デザイン、前も酷かったけど今はもっと酷いね)Category-Related Tags。なになに? MTCategories と MTSubCategories の違いは多機能かどうかってことね。ほどなく sort_method プロパティを発見。しかし

Please see the example for more details

とあるわりには、例とかネェじゃん。正直に言いますね。最初は日本の sixaprt が出してる日本語版を読んでました。まぁきっと日本の誰かが手を抜いたんだろうと思って、本家を当たり直しても結局一緒。何じゃこりゃ!

で、Google 先生にお伺いすると、殆ど同じ文面を発見。しかしリンク切れなので、キャッシュです。

SubCategories Plugin by David Raynes

この一緒っぷりだとおそらく Sixaprt が正規ファイルとして買収なり採用なりしたんでしょう。で、これには例がついてます。Perl は殆ど知らないので、いい加減に調整してやってみる。うまく行った。上の Google Cache が切れたらアレだから、以下の Extend に code を付けておきます。

しかし、MovableType のタグ構造はよくわからん。いや、わかりにくいし、ドキュメントが貧弱。

package GRF::catsorting;
my %category_priorities = (
# I want 'MT Plugins' to appear before 'MT Brainstorming'
# followed by the rest
	'Trivia' => 1,
	'School' => 2,
	'Sticky Memo' => 4,
	'Tech' => 3,
	'diary' => 5,
# And I want 'SubCategories' to be the first plugin listed,
# followed by 'Entry' and then the rest of the plugins
	'Web' => 2,
	'MovableType' => 1
);
sub cat_sort ($$) {
	my ($a, $b) = @_;
	my $a_pri = $category_priorities{$a->label} || 1000;
	my $b_pri = $category_priorities{$b->label} || 1000;
	unless ($a_pri == 1000 && $b_pri == 1000) {
	# At least one of them has a defined priority
	# so sort on that
	return $a_pri <=> $b_pri;
	}
	# Both are the default value (1000)
	# so sort alphabetically
	return $a->label cmp $b->label;
}

簡単に変えなきゃいけないとこだけ解説すると…

1行目:package...
このスクリプトの置き場。 /mt/extlib/GRF/catsorting.pm としたので上のようになります。
5行目〜:’Trivia' =>...
トップレヴェルカテゴリの順番。数字の小さい順に並びます。配列しての並び順は関係ない。
12行目〜:’Web' =>...
僕の場合、Tech に Web と MovableType というサブカテゴリのがあるのだけどそれは別に用意する。同じく数字の小さい順に並びます。

例えばトップレベルに3つあるんだったら、それは飛び飛びの番号じゃダメで、必ず 1〜3 の順位を付ける、と。っていうか下の cat_sort を理解すればなんでかわかるんだろうけど…わかんないんで、今日はピーコ厨です。

Comment:8

Alexavia:2011-08-20 (Sat) 10:25

Thanks for the great info dog I owe you bgiigty.

izbchdxfas:2011-08-22 (Mon) 09:07

lghVeZ gbgyzaawgmji

jtfbheyaxo:2011-08-25 (Thu) 11:49

ciPyhP axspddidpsne

air jordan shoes:2011-10-01 (Sat) 23:36

It is nice to find a site about my interest. My first visit to your site is been a big help. Thank you for the efforts you been putting on making your site such an interesting and informative place to browse through. I’ll be visiting your site again to gather some more valuable information. You truly did a good job.

ugg classic tall:2011-10-14 (Fri) 22:49

I wanted to drop you a quick note to express my thanks. I’ve been following your bve picked up a ton of good information as well as enjoyed the way you’ve structured your site.

Louis Vuitton Outlet:2011-10-22 (Sat) 02:28

http://www.shop-louisvuitton.org

North face jackets:2011-12-22 (Thu) 21:32

Good article! Thank you so much for sharing this post.

Cheap Handbags:2012-01-04 (Wed) 21:05

Thank you for sharing the nice post with useful information.

Comment Form

Remember Me?


Trackback:0

TrackBack URL for this entry
http://blogs.grf-design.com/mt/mt-tb.cgi/65
Listed below are links to weblogs that reference
Category Sorting from The Croton

Return to Page Top