【Movable Type 6】年度別カテゴリ一覧

年度別(4月始まり3月終わり)にカテゴリ一覧を出した際の忘備録。
環境はMovable Type Pro version 6.2.6になります。

アーカイブテンプレート:記事リスト(年別)

<mt:SetVarBlock name="this_year"><mt:ArchiveDate format="%Y"></mt:SetVarBlock>
<mt:SetVarBlock name="this_year_manth"><mt:ArchiveDate format="%Y">04</mt:SetVarBlock>
<mt:SetVarBlock name="next_year_manth"><MTVar name="this_year" value="1" op="+">03</mt:SetVarBlock>
<ul><!--<mt:ArchiveList archive_type="Category"><MTSetVarBlock name="EntryYear"><mt:Entries><$mt:EntryDate format="%Y%m" setvar="year"$><mt:If name="year" ge="$this_year_manth"><mt:If name="year" le="$next_year_manth">1</mt:if></mt:if></mt:Entries></MTSetVarBlock><mt:If name="EntryYear" ge="1">
	--><li><a href="<$mt:CategoryArchiveLink$>"><$mt:Categorylabel$>(<$mt:CategoryCount$>)</a></li><!--</mt:If></mt:ArchiveList>
--></ul>

▼リストの年を変数に設定(このファイルで呼び出す記事は何年か?)

<mt:SetVarBlock name="this_year"><mt:ArchiveDate format="%Y"></mt:SetVarBlock>

▼年度の初めを変数に設定

<mt:SetVarBlock name="this_year_manth"><mt:ArchiveDate format="%Y">04</mt:SetVarBlock>

変数”this_year”の末尾に04を追加して、年度の初めを設定します。
変数”this_year”が「2018」なら、変数”this_year_manth”は「201804」になります。

▼年度の終わりを変数に設定

<mt:SetVarBlock name="next_year_manth"><MTVar name="this_year" value="1" op="+">03</mt:SetVarBlock>

変数”this_year”に「value=”1″ op=”+”(1を足して)」、来年を取得します。
変数”this_year”が「2018」なら、「value=”1″ op=”+”(1を足して)」、「2019」になります。
来年の末尾に03を追加。
変数”this_year”が「2018」なら、変数”next_year_manth”は「201903」になります。

▼カテゴリーでアーカイブ一覧

<mt:ArchiveList archive_type="Category">

▼カテゴリーに登録された記事の年月を変数”year”に設定

<mt:Entries><$mt:EntryDate format="%Y%m" setvar="year"$>

▼変数”year”が年度の初め(変数”next_year_manth”)以上で

<mt:If name="year" ge="$this_year_manth">

▼変数”year”が年度の終わり(変数”next_year_manth”)以下だったら1を代入する。

<mt:If name="year" le="$next_year_manth">1

結果、年度の初め~年度の終わりの間に登録された記事のあるカテゴリーは変数”EntryYear”に1以上が収まる。
例えば、
カテゴリー1 登録記事2016/01/01
カテゴリー2 登録記事2018/04/01,2019/01/01
カテゴリー3 登録記事2018/04/01,2019/01/01,2019/04/01
上記を2018年度の記事リストとして出した時には、
変数”EntryYear”には以下の様に数字が入る。
カテゴリー1 変数”EntryYear”空
カテゴリー2 変数”EntryYear”11
カテゴリー3 変数”EntryYear”11

▼変数”EntryYear”が1以上なら一覧に表示される。

<mt:If name="EntryYear" ge="1">

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください