TopMovable Typeカスタマイズカテゴリー > sort_method モディファイア(その1)
2010年1月27日

sort_method モディファイア(その1)

Posted at January 27,2010 3:37 AM
Category:[カテゴリー]
Tag:[, , ]

Movable Type の MTSubCategories タグや MTTopLevelCategories タグでは sort_method というカテゴリを並び替えるモディファイアが利用可能です。

ネットで情報を検索すると、sort_method のサンプルで大体同じソースコードが登場するのですが、発信元は David Raynes 氏の SubCategories プラグインのようです。

SubCategories プラグイン

また、よくみかけるソースコードは以下にありました。

SubCategories Plugin Documentation

package rayners::CategorySorting;
 
my %category_priorities = (
# I want 'MT Plugins' to appear before 'MT Brainstorming'
# followed by the rest
    'MT Plugins' => 1
    'MT Brainstorming' => 2,
 
# And I want 'SubCategories' to be the first plugin listed,
# followed by 'Entry' and then the rest of the plugins
 
    'SubCategories' => 1,
    'Entry' => 2,
);
 
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;
}
Posted by yujiro   このページの先頭に戻る
関連記事
この記事を読んだ人はこんな記事も読んでいます
人気エントリー
Hatena Hot Entries
Hatena Entries
トラックバックURL


コメントする
greeting

*必須

*必須(非表示)


ご質問のコメントの回答については、内容あるいは多忙の場合、1週間以上かかる場合があります。また、すべてのご質問にはお答えできない可能性があります。予めご了承ください。

太字 イタリック アンダーライン ハイパーリンク 引用
[サインインしない場合はここにCAPTCHAを表示します]

コメント投稿後にScript Errorや500エラーが表示された場合は、すぐに再送信せず、ブラウザの「戻る」ボタンで一旦エントリーのページに戻り(プレビュー画面で投稿した場合は、投稿内容をマウスコピーしてからエントリーのページに戻り)、ブラウザをリロードして投稿コメントが反映されていることを確認してください。

コメント欄に(X)HTMLタグやMTタグを記述される場合、「<」は「&lt;」、「>」は「&gt;」と入力してください。例えば「<$MTBlogURL$>」は「&lt;$MTBlogURL$&gt;」となります(全て半角文字)

Now loading...
Introduction
Entries of this Category
Recent Entries
Recent Comments
Recent Trackbacks
QRcode

現在停止中です
携帯電話からこのQRcodeを撮影することで携帯用URLを取得することができます

URI for cellular phones
ギターに入った猫
Styles
Font Size
Default
For defective color vision
Gray Scale
RGB Color
Search this site

このブログをメールで購読する by:FeedBurner

loading ...
Categories
Monthly Archives
BlogPeople
Syndicate this site
FeedBurner(RSS1.0/RSS2.0/Atom)
Counter
これまでのアクセス
クリエイティブ・コモンズ・ライセンス
Powered by
Movable Type 5.12