Movable Type 7のコンテンツデータ(コンテンツタイプアーカイブ)をページ分割する方法
小粋空間 » Movable Type » カスタマイズ » ページ分割 » Movable Type 7のコンテンツデータ(コンテンツタイプアーカイブ)をページ分割する方法
Movable Type 7のコンテンツデータ(コンテンツタイプアーカイブ)をページ分割する方法を紹介します。
1.はじめに
Movable Type 7のコンテンツデータ(個別ページ)をページ分割する方法です。
ページ分割にはPageButeプラグインを利用します。
テンプレート種別でいうところの、「コンテンツタイプリストアーカイブ」をページ分割するのは情報があるようですが、「コンテンツタイプアーカイブ」をページ分割する情報がないようなので、本記事で紹介します。
なお、分割するにあたっては下記の条件となります。
- 分割対象はコンテンツタイプ内の特定のコンテンツフィールド(テキスト(複数行))のみ
分割する方法は2つあるので、順番に説明します。
サンプルでは、分割するコンテンツフィールドの名前を「本文」としています。
2.コンテンツデータ(コンテンツタイプアーカイブ)をページ分割する(その1:コメント挿入)
まず、コンテンツタイプアーカイブテンプレートを次のように設定します。
前半の5行がコンテンツフィールドのページ分割、残りの部分はごちゃごちゃしてますがページネーションのためのテンプレート(Pagebuteの公式サイトから引用)です。
<mt:PageContents count="1">
<mt:ContentField content_field="本文">
<mt:ContentFieldValue><$mt:PageSeparator$>
</mt:ContentField>
</mt:PageContents>
<mt:Pagination>
<mt:PaginationHeader>
<div class="pagenate"><ul>
<mt:IfPaginationFirst><li><a class="link_before" href="<$mt:PaginationFirst$>"><<</a></li></mt:IfPaginationFirst>
<mt:IfPaginationPrev><li><a class="link_before" href="<$mt:PaginationPrev$>"><</a></li></mt:IfPaginationPrev>
</mt:PaginationHeader>
<mt:IfPaginationCurrent>
<mt:ignore>現在のページ</mt:ignore>
<li><span><mt:PaginationLink element="number"></span></li>
<mt:Else>
<mt:ignore>それ以外(遷移用のリンクあり)</mt:ignore>
<li><a href="<$mt:PaginationLink$>"><$mt:PaginationLink element="number"$></a></li>
</mt:IfPaginationCurrent>
<mt:PaginationFooter>
<mt:IfPaginationNext><li><a class="link_next" href="<$mt:PaginationNext$>">></a></li></mt:IfPaginationNext>
<mt:IfPaginationLast><li><a class="link_next" href="<$mt:PaginationLast$>">>></a></li></mt:IfPaginationLast>
</ul></div>
</mt:PaginationFooter>
</mt:Pagination>
そして、コンテンツデータ作成時、コンテンツフィールド「本文」に対し、ページ分割したい箇所に
<!-- Separator for PageBute -->
を挿入します。
たとえば以下のように挿入します。
本文(1ページ目)
:
本文(1ページ目)
<!-- Separator for PageBute -->
本文(2ページ目)
:
本文(2ページ目)
<!-- Separator for PageBute -->
本文(3ページ目)
:
本文(3ページ目)
3.コンテンツデータ(コンテンツタイプアーカイブ)をページ分割する(その2:mtevalモディファイアを利用)
まず、コンテンツタイプアーカイブテンプレートを次のように設定します。
<mt:PageContents count="1">
<mt:ContentField content_field="本文">
<mt:ContentFieldValue mteval="1"><$mt:PageSeparator$>
</mt:ContentField>
</mt:PageContents>
<mt:Pagination>
<mt:PaginationHeader>
<div class="pagenate"><ul>
<mt:IfPaginationFirst><li><a class="link_before" href="<$mt:PaginationFirst$>"><<</a></li></mt:IfPaginationFirst>
<mt:IfPaginationPrev><li><a class="link_before" href="<$mt:PaginationPrev$>"><</a></li></mt:IfPaginationPrev>
</mt:PaginationHeader>
<mt:IfPaginationCurrent>
<mt:ignore>現在のページ</mt:ignore>
<li><span><mt:PaginationLink element="number"></span></li>
<mt:Else>
<mt:ignore>それ以外(遷移用のリンクあり)</mt:ignore>
<li><a href="<$mt:PaginationLink$>"><$mt:PaginationLink element="number"$></a></li>
</mt:IfPaginationCurrent>
<mt:PaginationFooter>
<mt:IfPaginationNext><li><a class="link_next" href="<$mt:PaginationNext$>">></a></li></mt:IfPaginationNext>
<mt:IfPaginationLast><li><a class="link_next" href="<$mt:PaginationLast$>">>></a></li></mt:IfPaginationLast>
</ul></div>
</mt:PaginationFooter>
</mt:Pagination>
そして、コンテンツデータ作成時、コンテンツフィールド「本文」に対し、ページ分割したい箇所に
<$mt:PageSeparator$>
を挿入します。
たとえば以下のように挿入します。
本文(1ページ目)
:
本文(1ページ目)
<$mt:PageSeparator$>
本文(2ページ目)
:
本文(2ページ目)
<$mt:PageSeparator$>
本文(3ページ目)
:
本文(3ページ目)
3.その他のコンテンツフィールドについて
ページ分割対象でないコンテンツフィールドは、MTPageContentsタグの外に書くか、中に書くかで表示方法が変わります。
- MTPageContentsタグの中に書く:1ページ目のみに表示
- MTPageContentsタグの外に書く:すべてのページに表示
1.の書き方の例は下記です。
<mt:PageContents count="1">
商品名:<mt:ContentField content_field="商品名"><mt:ContentFieldValue></mt:ContentField>
価格:<mt:ContentField content_field="価格"><mt:ContentFieldValue></mt:ContentField>
<mt:ContentField content_field="本文">
<mt:ContentFieldValue mteval="1"><$mt:PageSeparator$>
</mt:ContentField>
</mt:PageContents>
:
2.の書き方の例は下記です。
商品名:<mt:ContentField content_field="商品名"><mt:ContentFieldValue></mt:ContentField>
価格:<mt:ContentField content_field="価格"><mt:ContentFieldValue></mt:ContentField>
<mt:PageContents count="1">
<mt:ContentField content_field="本文">
<mt:ContentFieldValue mteval="1"><$mt:PageSeparator$>
</mt:ContentField>
</mt:PageContents>
: