カテゴリーごとにテンプレートを切り替える

July 5, 2006 7:32 PM | no comments | no trackback

カテゴリーごとにテンプレートを切り替える方法です。
導入例(MT 3.2-ja-2 で確認)

カテゴリーごとのテンプレートをモジュールに登録しておいて、カテゴリー・アーカイブのテンプレートをこのようにします。

<MTIfIsDescendant parent="News">   <$MTInclude module="NewsArchive"$> <MTElse>   <MTIfIsDescendant parent="Software">     <$MTInclude module="SoftwareArchive"$>   <MTElse>     <MTIfIsDescendant parent="Topics">       <$MTInclude module="TopicsArchive"$>     </MTIfIsDescendant>   </MTElse>   </MTIfIsDescendant> </MTElse> </MTIfIsDescendant>

この例だと、「News」カテゴリーには、モジュールの「NewsArchive」というように、<$MTInclude module="..."$> を使って読み込んでいます。

2006/07/05 追記

サブカテゴリーはどうするの?と質問を頂きました。

MTIfIsDescendant タグは、「現在のカテゴリーが、指定したカテゴリーの子孫であるかどうかを判定する条件タグ」です。
例えば、上記の例の「News」カテゴリーのサブカテゴリーに「Sports」があるとします。
<MTIfIsDescendant parent="News">...と最初にしてしまうと、「News」の子孫である「Sports」にもマッチしてしまう為、「階層が下のものから条件分岐」となるわけです。

<MTIfIsDescendant parent="Sports"> <$MTInclude module="NewsSportsArchive"$> <MTElse>   <MTIfIsDescendant parent="News">   : </MTIfIsDescendant>   </MTElse> </MTIfIsDescendant>

entry tags

trackback

  • http://miwa.offside.ne.jp/cgi-bin/mtos/mt-tb.cgi/5

comments