Skyward Design

Blog Webクリエイターの日々の覚え書き

ホーム > Blog > Web制作 > Movable Type > スタティックパブリッシングのページ分割機能を試す

スタティックパブリッシングのページ分割機能を試す

Posted by Hideki at 2009年9月12日 17:32

タグ:

ソースを示していますが、まだまだ引き続き実験中です。

MovableType.orgに掲載された記事、「Pagination for Static Templates」を参考にし、スタティックパブリッシングのページ分割機能を試してみました。

この機能は、Movable Type 4.3から追加されたものです。1ページ目は生成されたHTMLファイルを表示し、2ページ目以降はmt-search.cgiを用いて適宜分割されたページを表示するようです。

今回はテストとして、MovableType.org記事内のテンプレートのソースを参考にし、インデックステンプレートのメインページの分割を行ってみました。記事概要と他のページへ遷移するためのナビゲーションは、次のようなテンプレートを用いて表示できました。

<mt:Ignore><!-- ページに表示するエントリー数 --></mt:Ignore>
<$mt:Var name="entries_per_page" value="3"$>

<mt:If name="search_results">
    <mt:SearchResults>
        <$mt:Include module="ブログ記事の概要"$>
    </mt:SearchResults>
<mt:Else>
    <mt:Entries limit="$entries_per_page">
        <mt:Ignore><!-- 記事の出力 --></mt:Ignore>
        <$mt:Include module="ブログ記事の概要"$>
    </mt:Entries>
</mt:If>

<mt:Ignore><!-- ページ分割表示のためのURLクエリ文字列生成 --></mt:Ignore>
<mt:SetVarBlock name="search_link">
    <$mt:CGIPath$><$mt:SearchScript$>?IncludeBlogs=<$mt:BlogID$>
    &template_id=<$mt:BuildTemplateID$>
    &limit=<$mt:Var name="entries_per_page"$>
    &archive_type=Index
    &page=
</mt:SetVarBlock>
<mt:Ignore><!-- 空白除去 --></mt:Ignore>
<$mt:Var name="search_link" strip="" trim="1" setvar="search_link"$>

<mt:Ignore><!-- ページングナビ生成 --></mt:Ignore>
<mt:SetVarBlock name="pagination_navigation">
    <mt:If name="search_results">
        <mt:Ignore><!-- 動的ページ用ナビゲーション --></mt:Ignore>
        <mt:IfPreviousResults>
            <li class="previousPage"><a href="<$mt:PreviousLink$>" rel="prev" onclick="return swapContent(-1);"><< 前へ</a></li>
        </mt:IfPreviousResults>
        <mt:PagerBlock>
            <mt:IfCurrentPage>
                <li><em><$mt:Var name="__value__"$></em></li>
            <mt:Else>
                <li><a href="<$mt:PagerLink$>"><$mt:Var name="__value__"$></a></li>
            </mt:IfCurrentPage>
        </mt:PagerBlock>
        <mt:IfMoreResults>
            <li class="nextPage"><a href="<$mt:NextLink$>" rel="next" onclick="return swapContent();">次へ >></a></li>
        </mt:IfMoreResults>
    <mt:Else>
        <mt:Ignore><!-- 静的ページ用ナビゲーション --></mt:Ignore>
        <mt:If name="archive_template">
            <$mt:ArchiveCount setvar="total_entries"$>
        <mt:Else>
            <$mt:BlogEntryCount setvar="total_entries"$>
        </mt:If>
        <mt:Ignore><!-- 総エントリー数がページに表示するエントリー数を上回る場合はナビを生成 --></mt:Ignore>
        <mt:If name="total_entries" gt="$entries_per_page">
            <mt:Ignore><!-- Set the total number of entries to iterate through the pages. --></mt:Ignore>
            <mt:Ignore><!-- IF total entries divided by entries per page is a whole number. --></mt:Ignore>
            <mt:If name="total_entries" op="%" value="$entries_per_page" eq="0">
                <mt:Ignore><!-- Set total pages to total entries divided by entries per page. --></mt:Ignore>
                <$mt:Var name="total_entries" op="/" value="$entries_per_page" setvar="total_pages"$>
            <mt:Else>
                <mt:Ignore><!-- Get the remainder when dividing total entries by entries per page. --></mt:Ignore>
                <$mt:Var name="total_entries" op="%" value="$entries_per_page" setvar="remainder"$>
                <mt:Ignore><!-- Subtract remainder from total entries. --></mt:Ignore>
                <$mt:Var name="total_entries" op="-" value="$remainder" setvar="total_entries"$>
                <mt:Ignore><!-- Determine total pages by dividing total entries (minus remainder) by entries per page. --></mt:Ignore>
                <$mt:Var name="total_entries" op="/" value="$entries_per_page" setvar="total_pages"$>
                <mt:Ignore><!-- Add one page to handle the remainder of entries. --></mt:Ignore>
                <$mt:SetVar name="total_pages" op="++"$>
            </mt:If>
            
            <mt:For from="1" to="$total_pages" step="1">
                <mt:If name="__first__">
                    <li><em><$mt:Var name="__index__"$></em></li>
                <mt:Else>
                    <li><a href="<$mt:Var name="search_link"$><$mt:Var name="__index__"$>"><$mt:Var name="__index__"$></a></li>
                </mt:If>
            </mt:For>
            <mt:Ignore><!-- 「次へ」のリンク生成 --></mt:Ignore>
            <li class="nextPage"><a href="<$mt:Var name="search_link"$>2" rel="next">次へ >></a></li>
        </mt:If>
    </mt:If>
</mt:SetVarBlock>

<mt:Ignore><!-- ナビゲーションの出力 --></mt:Ignore>
<mt:If name="pagination_navigation">
    <ul class="pagination">
        <$mt:Var name="pagination_navigation"$>
    </ul>
</mt:If>

MovableType.orgのサンプルコードとの違い

  • 「Previous」「Next」を、「前へ」「次へ」と日本語で表示
  • 「ブログ記事の概要」表示部分を修正(mt-search.cgiで表示する際に上手く表示できなかったため)
  • ページナビゲーションを、ul要素などを用いてマークアップ

コメント

現在この記事へのコメントはありません。

コメント投稿フォーム

トラックバック

トラックバックURL:
http://www.skyward-design.net/mt5/mt-tb.cgi/78

Copyright © 2009 Skyward Design All Rights Reserved.

Powered by Movable Type 5.0