試しに、月別ブログ記事リストとカテゴリ別ブログ記事リストにページ送りを導入してみました。
MTOS(MT5)では、ページ送り機能が標準で実装されたという事なので試してみました。
いろいろググッてみたんですが、そのものずばりの適当なページがヒットしませんでしたので、 movabletype.org にのっていた標準テンプレートを日本語に直して使用してみました。
メインページにもページ送りを実装できるようですが、上手く動かないとのコメントが多く寄せられているので、暇な時にでも挑戦してみます。
ソース
Pagination for Static Templates (movabletype.org)に掲載されている英語版のテンプレートを使用。標準テンプレが二つ掲載されていますが、下の方の"Entry Listing"を使います。
これを丸々コピーして、エディタで日本語にしなければならない部分と、1ページに表示する件数を設定するだけで上手く動きます。
変更する場所
モジュール名や記述を単純に日本語に直すだけなので簡単です。赤字は、たぶん変更しないといけない場所。青字は、テキストなので変更してもしなくてもよいところ。緑字は、ページ当たりの表示記事数の設定数値です。
変更する部分を行番号と共にメモしておきます。インデントは省略してます。
8: <$mt:Include module="HTMLヘッダー"$> 9: <title><$mt:BlogName encode_html="1"$>: <$mt:ArchiveTitle$>アーカイブ</title> 22: <$mt:Include module="バナーヘッダー"$> 34: <h1 id="page-title" class="archive-title"><$mt:ArchiveTitle$>アーカイブ</h1> 37: <h1 id="page-title" class="archive-title"><strong><$mt:ArchiveTitle$></strong>カテゴリーの記事</h1> 42: <$mt:Var name="entries_per_page" value="5"$> 71: <$mt:Include module="ブログ記事の概要"$> 140: <a href="<$mt:Link template="main_index"$>">メインページ</a> | 141: <a href="<$mt:Link template="archive_index"$>">アーカイブ</a> 149: <$mt:Include module="サイドバー"$> 156: <$mt:Include module="バナーフッター"$>
これで全部だと思います。
42行目のところで、ページ当たりの表示件数を設定できます。オリジナルのソースは2件になってますが、このブログでは5件にしてあります。
変更したテンプレートを、アーカイブテンプレートのカテゴリ別ブログ記事リストと月別ブログ記事リストにコピペで上書きし、再構築したら完了です。
とりあえず、上手く動いている様子ですね。
注意する事
ダイナミックでは、上手く動きません。
一枚目のページで、カテゴリーや月別の記事数に関係なく、総記事数分のページ送りリンクが生成されてしまうようです。スタティックにすると、正常に動いているようですね。
後のため、この記事を書いた時点でのオリジナルと改変後のコードを貼り付けときます。
オリジナルのコード
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" id="sixapart-standard">
<head>
<mt:If name="archive_template">
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="<$mt:Link template="rsd"$>" />
</mt:If>
<$mt:Include module="HTML Head"$>
<title><$mt:BlogName encode_html="1"$>: <$mt:ArchiveTitle$> Archives</title>
<mt:If name="archive_template">
<mt:If name="datebased_archive">
<mt:ArchivePrevious><link rel="prev" href="<$mt:ArchiveLink$>" title="<$mt:ArchiveTitle encode_html="1"$>" /></mt:ArchivePrevious>
<mt:ArchiveNext><link rel="next" href="<$mt:ArchiveLink$>" title="<$mt:ArchiveTitle encode_html="1"$>" /></mt:ArchiveNext>
</mt:If>
</mt:If>
</head>
<body id="<$mt:BlogTemplateSetID$>" class="mt-archive-listing mt-<$mt:Var name="archive_class"$> <$mt:Var name="page_layout"$>">
<div id="container">
<div id="container-inner">
<$mt:Include module="Banner Header"$>
<div id="content">
<div id="content-inner">
<div id="alpha">
<div id="alpha-inner">
<mt:If name="archive_template">
<mt:If name="datebased_archive">
<mt:Ignore><!-- Title for category-monthly entry listings --></mt:Ignore>
<h1 id="page-title" class="archive-title"><$mt:ArchiveTitle$> Archives</h1>
<mt:Else>
<mt:Ignore><!-- Title for category entry listings --></mt:Ignore>
<h1 id="page-title" class="archive-title">Recently in <em><$mt:ArchiveTitle$></em> Category</h1>
</mt:If>
</mt:If>
<mt:Ignore><!-- Set the number of entries displayed on each page. --></mt:Ignore>
<$mt:Var name="entries_per_page" value="2"$>
<mt:Ignore><!-- Construct the url for querying entries. --></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"$>
<mt:If name="archive_template">
&archive_type=<$mt:ArchiveType$>
<mt:If name="datebased_archive">
&year=<$mt:ArchiveDate format='%Y'$>&month=<$mt:ArchiveDate format='%m'$>&day=<$mt:ArchiveDate format='%d'$>
</mt:If>
<mt:If name="category_archive">
&category=<$mt:CategoryID$>
</mt:If>
<mt:If name="author_archive">
&author=<$mt:AuthorID$>
</mt:If>
<mt:Else>
&archive_type=Index
</mt:If>
&page=
</mt:SetVarBlock>
<mt:Ignore><!-- Strip spaces and trim value. --></mt:Ignore>
<$mt:Var name="search_link" strip="" trim="1" setvar="search_link"$>
<mt:Ignore><!-- Entries loop for publishing static and dynamic pages. --></mt:Ignore>
<mt:Entries limit="$entries_per_page" search_results="1">
<mt:Ignore><!-- Use the Entry Summary module for each entry published on this page. --></mt:Ignore>
<$mt:Include module="Entry Summary"$>
</mt:Entries>
<mt:Ignore><!-- Create pagination navigation. Condition based upon if page is statically or dynamically rendered using the search_results variable. --></mt:Ignore>
<mt:SetVarBlock name="pagination_navigation">
<mt:If name="search_results">
<mt:Ignore><!-- Navigation for dynamic pages (same as navigation found in the Search Results system template). --></mt:Ignore>
<mt:IfPreviousResults>
<a href="<$mt:PreviousLink$>" rel="prev" onclick="return swapContent(-1);">< Previous</a>
</mt:IfPreviousResults>
<mt:PagerBlock>
<mt:IfCurrentPage>
<$mt:Var name="__value__"$>
<mt:Else>
<a href="<$mt:PagerLink$>"><$mt:Var name="__value__"$></a>
</mt:IfCurrentPage>
</mt:PagerBlock>
<mt:IfMoreResults>
<a href="<$mt:NextLink$>" rel="next" onclick="return swapContent();">Next ></a>
</mt:IfMoreResults>
<mt:Else>
<mt:Ignore><!-- Navigation for statically published page. --></mt:Ignore>
<mt:If name="archive_template">
<$mt:ArchiveCount setvar="total_entries"$>
<mt:Else>
<$mt:BlogEntryCount setvar="total_entries"$>
</mt:If>
<mt:Ignore><!-- If blog contains more entries than the number of entries to display per page. --></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 ` 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:Ignore><!-- Loop through total pages, creating links to all but the first page (which is the current page). --></mt:Ignore>
<mt:For from="1" to="$total_pages" step="1">
<mt:If name="__first__">
<$mt:Var name="__index__"$>
<mt:Else>
<a href="<$mt:Var name="search_link"$><$mt:Var name="__index__"$>"><$mt:Var name="__index__"$></a>
</mt:If>
</mt:For>
<mt:Ignore><!-- Hard-coded link to the next page (page 2). --></mt:Ignore>
<a href="<$mt:Var name="search_link"$>2" rel="next">Next »</a>
</mt:If>
</mt:If>
</mt:SetVarBlock>
<mt:Ignore><!-- Strip space and trim navigation code. --></mt:Ignore>
<$mt:Var name="pagination_navigation" strip=" " trim="1" setvar="pagination_navigation"$>
<div class="content-nav">
<mt:Ignore><!-- Output variable if exists. --></mt:Ignore>
<$mt:Var name="pagination_navigation" strip=" " trim="1" setvar="pagination_navigation"$>
<mt:If name="pagination_navigation">
<div class="pagination-navigation">
<$mt:Var name="pagination_navigation"$>
</div>
</mt:If>
<mt:ArchivePrevious><a href="<$mt:ArchiveLink$>">« <$mt:ArchiveTitle$></a> |</mt:ArchivePrevious>
<a href="<$mt:Link template="main_index"$>">Main Index</a> |
<a href="<$mt:Link template="archive_index"$>">Archives</a>
<mt:ArchiveNext>| <a href="<$mt:ArchiveLink$>"><$mt:ArchiveTitle$> »</a></mt:ArchiveNext>
</div>
</div>
</div>
<$mt:Include module="Sidebar"$>
</div>
</div>
<$mt:Include module="Banner Footer"$>
</div>
</div>
</body>
</html>
改変後のコード
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" id="sixapart-standard">
<head>
<mt:If name="archive_template">
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="<$mt:Link template="rsd"$>" />
</mt:If>
<$mt:Include module="HTMLヘッダー"$>
<title><$mt:BlogName encode_html="1"$>: <$mt:ArchiveTitle$>アーカイブ</title>
<mt:If name="archive_template">
<mt:If name="datebased_archive">
<mt:ArchivePrevious><link rel="prev" href="<$mt:ArchiveLink$>" title="<$mt:ArchiveTitle encode_html="1"$>" /></mt:ArchivePrevious>
<mt:ArchiveNext><link rel="next" href="<$mt:ArchiveLink$>" title="<$mt:ArchiveTitle encode_html="1"$>" /></mt:ArchiveNext>
</mt:If>
</mt:If>
</head>
<body id="<$mt:BlogTemplateSetID$>" class="mt-archive-listing mt-<$mt:Var name="archive_class"$> <$mt:Var name="page_layout"$>">
<div id="container">
<div id="container-inner">
<$mt:Include module="バナーヘッダー"$>
<div id="content">
<div id="content-inner">
<div id="alpha">
<div id="alpha-inner">
<mt:If name="archive_template">
<mt:If name="datebased_archive">
<mt:Ignore><!-- Title for category-monthly entry listings --></mt:Ignore>
<h1 id="page-title" class="archive-title"><$mt:ArchiveTitle$>アーカイブ</h1>
<mt:Else>
<mt:Ignore><!-- Title for category entry listings --></mt:Ignore>
<h1 id="page-title" class="archive-title"><strong><$mt:ArchiveTitle$></strong>カテゴリーの記事</h1>
</mt:If>
</mt:If>
<mt:Ignore><!-- Set the number of entries displayed on each page. --></mt:Ignore>
<$mt:Var name="entries_per_page" value="5"$>
<mt:Ignore><!-- Construct the url for querying entries. --></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"$>
<mt:If name="archive_template">
&archive_type=<$mt:ArchiveType$>
<mt:If name="datebased_archive">
&year=<$mt:ArchiveDate format='%Y'$>&month=<$mt:ArchiveDate format='%m'$>&day=<$mt:ArchiveDate format='%d'$>
</mt:If>
<mt:If name="category_archive">
&category=<$mt:CategoryID$>
</mt:If>
<mt:If name="author_archive">
&author=<$mt:AuthorID$>
</mt:If>
<mt:Else>
&archive_type=Index
</mt:If>
&page=
</mt:SetVarBlock>
<mt:Ignore><!-- Strip spaces and trim value. --></mt:Ignore>
<$mt:Var name="search_link" strip="" trim="1" setvar="search_link"$>
<mt:Ignore><!-- Entries loop for publishing static and dynamic pages. --></mt:Ignore>
<mt:Entries limit="$entries_per_page" search_results="1">
<mt:Ignore><!-- Use the Entry Summary module for each entry published on this page. --></mt:Ignore>
<$mt:Include module="ブログ記事の概要"$>
</mt:Entries>
<mt:Ignore><!-- Create pagination navigation. Condition based upon if page is statically or dynamically rendered using the search_results variable. --></mt:Ignore>
<mt:SetVarBlock name="pagination_navigation">
<mt:If name="search_results">
<mt:Ignore><!-- Navigation for dynamic pages (same as navigation found in the Search Results system template). --></mt:Ignore>
<mt:IfPreviousResults>
<a href="<$mt:PreviousLink$>" rel="prev" onclick="return swapContent(-1);">< Previous</a>
</mt:IfPreviousResults>
<mt:PagerBlock>
<mt:IfCurrentPage>
<$mt:Var name="__value__"$>
<mt:Else>
<a href="<$mt:PagerLink$>"><$mt:Var name="__value__"$></a>
</mt:IfCurrentPage>
</mt:PagerBlock>
<mt:IfMoreResults>
<a href="<$mt:NextLink$>" rel="next" onclick="return swapContent();">Next ></a>
</mt:IfMoreResults>
<mt:Else>
<mt:Ignore><!-- Navigation for statically published page. --></mt:Ignore>
<mt:If name="archive_template">
<$mt:ArchiveCount setvar="total_entries"$>
<mt:Else>
<$mt:BlogEntryCount setvar="total_entries"$>
</mt:If>
<mt:Ignore><!-- If blog contains more entries than the number of entries to display per page. --></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 ` 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:Ignore><!-- Loop through total pages, creating links to all but the first page (which is the current page). --></mt:Ignore>
<mt:For from="1" to="$total_pages" step="1">
<mt:If name="__first__">
<$mt:Var name="__index__"$>
<mt:Else>
<a href="<$mt:Var name="search_link"$><$mt:Var name="__index__"$>"><$mt:Var name="__index__"$></a>
</mt:If>
</mt:For>
<mt:Ignore><!-- Hard-coded link to the next page (page 2). --></mt:Ignore>
<a href="<$mt:Var name="search_link"$>2" rel="next">Next »</a>
</mt:If>
</mt:If>
</mt:SetVarBlock>
<mt:Ignore><!-- Strip space and trim navigation code. --></mt:Ignore>
<$mt:Var name="pagination_navigation" strip=" " trim="1" setvar="pagination_navigation"$>
<div class="content-nav">
<mt:Ignore><!-- Output variable if exists. --></mt:Ignore>
<$mt:Var name="pagination_navigation" strip=" " trim="1" setvar="pagination_navigation"$>
<mt:If name="pagination_navigation">
<div class="pagination-navigation">
<$mt:Var name="pagination_navigation"$>
</div>
</mt:If>
<mt:ArchivePrevious><a href="<$mt:ArchiveLink$>">« <$mt:ArchiveTitle$></a> |</mt:ArchivePrevious>
<a href="<$mt:Link template="main_index"$>">メインページ</a> |
<a href="<$mt:Link template="archive_index"$>">アーカイブ</a>
<mt:ArchiveNext>| <a href="<$mt:ArchiveLink$>"><$mt:ArchiveTitle$> »</a></mt:ArchiveNext>
</div>
</div>
</div>
<$mt:Include module="サイドバー"$>
</div>
</div>
<$mt:Include module="バナーフッター"$>
</div>
</div>
</body>
</html>
コメントする