1

同じ親ページを持つ子ページ間でnext-page等のナビゲーションを表示するプラグイン[WORDPRESS]

を探していたのですが、このあいだようやく発見しました。

投稿にはprevious_post_linkやnext_post_linkというテンプレートタグがあるのですが、ページにはなぜかない(と思う)のでこれまでは手動でナビゲーションを追加していました。

需要があるだろうからきっとプラグインがあるだろうと思って探してもずっと見つからず諦めかけていたのですが、先日何かの拍子に次のページを発見。
WordPress ? Support ≫ Prev/Next Page plugin? (wordpress Pages, not Posts)

earthman100氏によるVer0.6を適当な名前でphpファイルにしpluginsフォルダに入れて有効化すると動きました。(WP2.6)
まさしく探してたプラグインです。

子ページの最後にくると別の親ページへのリンクが表示されたのですが、それは不要なのでその部分のcodeを適当に間引いて使っています。(良くわからないまま適当に間引いているので無駄なcodeが残ってると思いますが。)

いちおう置いておきますので必要な方はどうぞ。

nextpreviouspageプラグイン

引数のデフォルトは

previous(next)_page($orderby = ‘post_date’, $link=’Next Page: %’, $before=”, $after=”, $title_attr=’Next Page: %’, $parent_id = 0)

引数については別のページによると
WordPress ? Support ≫ Next page (literally)

Parameters:

orderby: Method to order Pages in next/previous link hierarchy. Options are ‘post_date’ and ‘menu_order’ (Page order). Default is ‘post_date’.

link: Text displayed as the link. Use ‘%’ to display the Page’s title as link. Defaults to ‘Next Page: %’ / ‘Previous Page: %’

before: HTML or text to display before the link. There is no default.

after: HTML or text to display after the link. There is no default.

title_attr: Text displayed for the link’s title attribute. Use ‘%’ to display the Page’s title. Defaults to ‘Next Page: %’ / ‘Previous Page: %’

All you need to do is pass the current page’s parent ID into the function as explained below. This will limit the next and previous links to ONLY the brothers and sisters of that current page.

$orderby:ソートの仕方。管理画面で設定したページ順序か日付順か。
$link:リンクに出力する文字。%はページタイトルになるようです。
$before, $after:上記のリンクの前後につける文字列。
$title_attr:マウスオーバー時に表示される文字。
$parent_id:なんでしょうか?良くわからないのでそのままにしてます。ここの指定によってはリンクが子ページのみになったのでしょうか?分かる方は教えてください。

といったところでしょうか。

先ほどのページに乗っていた導入例は

<div id="prev_next_links">
<?php
$parentid = $post->post_parent;
previous_page('menu_order', '&lsaquo;&lsaquo; %', '<span class="prev_link">', '</span>', 'title_attr', $parentid); ?>

<?php next_page('menu_order', '% &rsaquo;&rsaquo;', '<span class="next_link">', '</span>', 'title_attr', $parentid); ?>
</div>

僕は$linkと$title_attrを変えて使用しています。