MT4.3は標準でページ分割機能が付いています。以前のバージョンでは「PageBute」や「MTPaginate(PHPを使用)」などのプラグインを使う必要がありました。
カテゴリアーカイブと月別アーカイブに、ページ分割機能をさくっと付ける方法を紹介します。
記事の概要を下記のコードでサンドするように設置するだけです。
<mt:Ignore><!-- ページ分割2ページ目以降の記事の表示数(mt-search.cgiを使用)$list_on_indexでauto扱い --></mt:Ignore>
<$mt:Var name="entries_per_page" value="3"$>
<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">
【記事の概要をここに入れます】
</mt:Entries>
<mt:Ignore><!-- ページ分割時のナビゲーション 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"$>
<mt:Ignore>HTML出力</mt:Ignore>
<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:Ignore><!--デフォルトのフッター-->
<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>
</mt:Ignore>
</div>
あとは、CSSで見た目を変更
.pagination-navigation {
font-size: 80%;
text-align: center;
}
参考させていただいたサイト
- Pagination for Static Templates【MovableType.org】
- Features of 4.3: Entry Pagination【MovableType.org】
- MT4.3: Entry Pagination【MAX ENGINEERRING】




コメントとトラックバック