News
2008年11月 4日
エントリー本文
Movable Type 4.2 検索結果ページのカスタマイズ:ページナビゲーションをプルダウンメニューにする
Movable Type 4.2 の検索結果ページのカスタマイズで、5回目は「ページナビゲーションをプルダウンメニューにする」を紹介します。
その5:ページナビゲーションをプルダウンメニューにする
デフォルトテンプレートや配布テンプレートでは、ページナビゲーションがテキストで表示されます。

分割されたページが少ないと良いのですが、こんなに多くなると見栄えがよくありません。

カスタマイズ後はページナビゲーションを次のようなプルダウンメニューにし、ナビゲーションのデザインをすっきりさせます。プルダウンメニューには表示中のページ番号を表示し、全体のページ数も表示します。

ページナビゲーションをプルダウンメニューにするには、次の変更を行ってください。修正内容はデフォルトテンプレート、配布テンプレート共通です。デフォルトテンプレートではナビゲーションのサブテンプレートが1行にまとめられているので、見やすいように適宜改行を入れています。
変更前:赤色を削除
<div class="content-nav">
<mt:IfPreviousResults>
<a href="<$mt:PreviousLink$>" rel="prev" onclick="return swapContent(-1);">< 前</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:Unless name="__last__"> </mt:Unless>
</mt:PagerBlock>
<mt:IfMoreResults>
<a href="<$mt:NextLink$>" rel="next" onclick="return swapContent();">次 ></a>
</mt:IfMoreResults>
</div>
変更後:青色を追加
<script type="text/javascript">
//<![CDATA[
function selectUrl(sel){
if(sel.options[sel.selectedIndex].value){
location.href = sel.options[sel.selectedIndex].value;
}
}
//]]>
</script>
<div class="content-nav">
<mt:ifPreviousResults>
<a href="<mt:previousLink />" rel="prev" onclick="return swapContent(-1);">< 前</a>
</mt:ifPreviousResults>
<form action="javascript:void()" style="display:inline">
<select name="select" onChange="selectUrl(this.form.select)">
<mt:pagerBlock>
<mt:ifCurrentPage>
<option value="<mt:pagerLink>" selected="selected"><mt:getVar name="__value__" /></option>
<mt:else>
<option value="<mt:pagerLink>"><mt:getVar name="__value__" /></option>
</mt:ifCurrentPage>
<mt:unless name="__last__"> </mt:unless>
</mt:pagerBlock>
</select>
</form>/<mt:totalPages />ページ
<mt:ifMoreResults>
<a href="<mt:nextLink />" rel="next" onclick="return swapContent();">次 ></a>
</mt:ifMoreResults>
</div>
関連記事
- その4:ナビゲーションを検索結果の上下に表示する
- その3:検索結果が1ページだけのときに「1」という表示をなくす
- その2:検索結果の見出しに(現在のページ/総ページ数)を表示する
- その1:1ページに表示数する件数を変更する
Posted by yujiro
ReTweet This!
この記事を読んだ人はこんな記事も読んでいます
人気エントリー
Hatena Hot Entries
Hatena Entries
トラックバックURL
コメントする
greeting
