- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
「テンプレートタグ/next post link」の版間の差分
細 (様式・リンク調整、未翻訳) |
(クリーンアップ。) |
||
(6人の利用者による、間の18版が非表示) | |||
1行目: | 1行目: | ||
− | {{ | + | {{CheckTrans}} |
<div id="Description"> | <div id="Description"> | ||
5行目: | 5行目: | ||
</div> | </div> | ||
− | + | このテンプレートタグは、現在の投稿から見て日付順で次の投稿へのリンクを表示します。個別投稿の[[用語集#Permalink|パーマリンク]]ページで使用します。 | |
− | + | <p class="information">標準の使い方(デフォルトの設定変更していない[[ループ]]内)では、<code>next_post_link</code> は現在の投稿より新しい投稿へのリンクを表示します。これは似た名前の <tt>[[テンプレートタグ/next_posts_link|next_posts_link]]</tt> が現在の複数投稿ページより<em>古い</em>ページへリンクするのと反対方向です。</p> | |
+ | |||
+ | このタグは[[The Loop|ループ]]内で使用しなければなりません。 | ||
<div id="Usage"> | <div id="Usage"> | ||
13行目: | 15行目: | ||
</div> | </div> | ||
− | <?php next_post_link( | + | <?php next_post_link( $format, $link, $in_same_term = false, $excluded_terms = <nowiki>''</nowiki>, $taxonomy = 'category' ); ?> |
− | + | ||
+ | <div id="Parameters"> | ||
+ | == パラメータ == | ||
+ | </div> | ||
+ | |||
+ | {{Parameter|$format|文字列|リンクの文字列の書式。リンクの前後に追加する文字を設定できます。「<tt>%link</tt>」と文字列内に表記すると「$link」(次のパラメータ)に置き換えられます。「<tt>Go to %link</tt>」とすると「Go to <nowiki><a href=...</nowiki>」となります。スタイルをつけるには HTML タグを入れます。|オプション|<tt>'%link &raquo;'</tt>}} | ||
+ | |||
+ | {{Parameter|$link|文字列|表示するリンクのテキスト。|オプション|<tt>%title</tt> – 次の投稿のタイトル}} | ||
+ | |||
+ | {{Parameter|$in_same_term|真偽値|現在の投稿と同じタクソノミー・ターム(例:カテゴリー)の投稿に限定するかどうか。<tt>'true'</tt> にすると現在のタクソノミー・タームがついた投稿だけを表示します。|オプション|<tt>false</tt>}} | ||
+ | |||
+ | <p class="information">'''注意:''' 現在の投稿に 2 つ以上のターム(例:親と子の両方)がついていた場合、どのタームがついた投稿へリンクするかは選べません。</p> | ||
+ | |||
+ | {{Parameter|$excluded_terms|文字列/配列|表示させたくない投稿のターム ID(例:カテゴリー ID)。複数のタームを除外するには配列にするか、コンマで区切ってください(例:<tt>array(1, 5)</tt> または <tt>'1,5'</tt>)。<!-- This argument used to accept a list of IDs separated by <tt>'and'</tt>, this was deprecated in WordPress 3.3 -->|オプション|<nowiki>''</nowiki>}} | ||
+ | |||
+ | {{Parameter|$taxonomy|文字列|タクソノミー。これは <tt>$in_same_term</tt> が true の場合に有効です。(WordPress 3.8 で追加)|オプション|<tt>'category'</tt>}} | ||
<div id="Examples"> | <div id="Examples"> | ||
23行目: | 40行目: | ||
=== 初期設定での使用 === | === 初期設定での使用 === | ||
</div> | </div> | ||
− | |||
− | <div | + | 次の投稿(投稿の作成日順)へのリンクを、そのタイトルと右アンギュラークォート(»)として表示します。 |
+ | |||
+ | <div style="border:1px solid blue; width:50%; margin: 20px; padding:10px">[[#Examples|Next Post Title »]]</div> | ||
− | + | <?php next_post_link(); ?> | |
<div id="Bold_Post_Title_As_Link"> | <div id="Bold_Post_Title_As_Link"> | ||
− | === | + | === リンクのタイトルを太字にする === |
</div> | </div> | ||
− | |||
− | + | 作成日順で次の投稿のタイトルを「strong」タグで囲んで表示します(ふつうは太字になって強調されます)。 | |
− | <?php next_post_link('<strong>%link</strong>'); ?> | + | <div style="border:1px solid blue; width:50%; margin: 20px; padding:10px">[[#Examples|<strong>Next Post Title</strong>]]</div> |
+ | |||
+ | <?php next_post_link( <nowiki>'<strong>%link</strong>'</nowiki> ); ?> | ||
<div id="Text_As_Link.2C_Without_Post_Title.2C_Within_Same_Category"> | <div id="Text_As_Link.2C_Without_Post_Title.2C_Within_Same_Category"> | ||
− | === | + | === 同じカテゴリー内で、リンクテキストに投稿タイトルを使わず任意の文字にする === |
</div> | </div> | ||
− | |||
− | + | 現在の投稿と同じカテゴリー内の次の投稿へのリンクを、テキストをカスタマイズして表示します。投稿タイトルは入れません。「Next post in category」というテキストはあなたの希望にあわせてカスタマイズできます。 | |
− | <?php next_post_link('%link', 'Next post in category', TRUE); ?> | + | <div style="border:1px solid blue; width:50%; margin: 20px; padding:10px">[[#Examples|Next post in category]]</div> |
+ | |||
+ | <?php next_post_link( '%link', 'Next post in category', TRUE ); ?> | ||
<div id="Within_Same_Category.2C_Excluding_One"> | <div id="Within_Same_Category.2C_Excluding_One"> | ||
− | === | + | === 同じカテゴリー内だが特定のカテゴリーを除外する === |
</div> | </div> | ||
− | |||
− | < | + | 13 番(カテゴリー ID の数値)のカテゴリーだけを除外して、同じカテゴリーの次の投稿へのリンクを表示します。除外したいカテゴリーの番号は自由に変えられます。複数のカテゴリーを除外するには「<tt>,</tt>」で区切ってください。 |
− | + | <div style="border:1px solid blue; width:50%; margin: 20px; padding:10px">[[#Examples|Next post in category]]</div> | |
− | <div id=" | + | <?php next_post_link( '%link', 'Next post in category', TRUE, '13' ); ?> |
− | == | + | |
+ | <div id="Within_Same_Taxonomy"> | ||
+ | === 同じタクソノミー内 === | ||
</div> | </div> | ||
− | ; | + | 同じタクソノミー・ターム内の次の投稿へのリンクを表示します。投稿フォーマットはタクソノミーのひとつなので、下記の例は同じ投稿フォーマットの次の投稿へリンクします。 |
− | + | ||
− | + | <div style="border:1px solid blue; width:50%; margin: 20px; padding:10px">[[#Examples|Next post in taxonomy]]</div> | |
− | + | ||
− | : | + | <?php next_post_link( '%link', 'Next post in taxonomy', TRUE, ' ', 'post_format' ); ?> |
− | + | ||
− | + | <!-- 冗長なので削除 gblsm 26-Jun-2015 | |
+ | == Notes == | ||
+ | See also [[Template Tags/previous_post_link|previous_post_link()]]. | ||
+ | --> | ||
+ | |||
+ | <div id="Resources"> | ||
+ | == 外部リソース == | ||
+ | </div> | ||
+ | |||
+ | * [http://digwp.com/2009/08/wordpress-page-navigation/ Digging into Wordpress - Definitive Guide to WordPress Page Navigation] | ||
+ | * [http://wordpress.org/support/topic/286131 Forum discussion on using a image with next_post_link] | ||
+ | |||
+ | <div id="Change_Log"> | ||
+ | == 変更履歴 == | ||
+ | </div> | ||
+ | |||
+ | 1.5.0 : 新規導入 | ||
+ | |||
+ | <div id="Source_File"> | ||
+ | == ソースファイル == | ||
+ | </div> | ||
+ | |||
+ | <tt>next_post_link()</tt> は {{Trac|wp-includes/link-template.php}} にあります。 | ||
<div id="Related"> | <div id="Related"> | ||
− | == | + | == 関連項目 == |
</div> | </div> | ||
− | |||
− | {{Tag | + | {{Pagination}} |
+ | |||
+ | {{Tag Footer}} | ||
− | {{ | + | {{原文|Function Reference/next_post_link|151999}} <!-- 12:27, 10 June 2015 Tex0gen 版 --> |
− | {{ | + | {{DEFAULTSORT:Next_post_link}} |
+ | [[Category:テンプレートタグ]] | ||
− | + | [[en:Function Reference/next_post_link]] | |
− | [[en: | + |
2015年6月27日 (土) 13:05時点における最新版
この項目「テンプレートタグ/next post link」は、翻訳チェック待ちの項目です。加筆、訂正などを通して、Codex ドキュメンテーションにご協力下さい。
目次
説明
このテンプレートタグは、現在の投稿から見て日付順で次の投稿へのリンクを表示します。個別投稿のパーマリンクページで使用します。
標準の使い方(デフォルトの設定変更していないループ内)では、next_post_link
は現在の投稿より新しい投稿へのリンクを表示します。これは似た名前の next_posts_link が現在の複数投稿ページより古いページへリンクするのと反対方向です。
このタグはループ内で使用しなければなりません。
使い方
<?php next_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ); ?>
パラメータ
- $format
- (文字列) (オプション) リンクの文字列の書式。リンクの前後に追加する文字を設定できます。「%link」と文字列内に表記すると「$link」(次のパラメータ)に置き換えられます。「Go to %link」とすると「Go to <a href=...」となります。スタイルをつけるには HTML タグを入れます。
- 初期値: '%link »'
- $link
- (文字列) (オプション) 表示するリンクのテキスト。
- 初期値: %title – 次の投稿のタイトル
- $in_same_term
- (真偽値) (オプション) 現在の投稿と同じタクソノミー・ターム(例:カテゴリー)の投稿に限定するかどうか。'true' にすると現在のタクソノミー・タームがついた投稿だけを表示します。
- 初期値: false
注意: 現在の投稿に 2 つ以上のターム(例:親と子の両方)がついていた場合、どのタームがついた投稿へリンクするかは選べません。
- $excluded_terms
- (文字列/配列) (オプション) 表示させたくない投稿のターム ID(例:カテゴリー ID)。複数のタームを除外するには配列にするか、コンマで区切ってください(例:array(1, 5) または '1,5')。
- 初期値: ''
- $taxonomy
- (文字列) (オプション) タクソノミー。これは $in_same_term が true の場合に有効です。(WordPress 3.8 で追加)
- 初期値: 'category'
用例
初期設定での使用
次の投稿(投稿の作成日順)へのリンクを、そのタイトルと右アンギュラークォート(»)として表示します。
<?php next_post_link(); ?>
リンクのタイトルを太字にする
作成日順で次の投稿のタイトルを「strong」タグで囲んで表示します(ふつうは太字になって強調されます)。
<?php next_post_link( '<strong>%link</strong>' ); ?>
同じカテゴリー内で、リンクテキストに投稿タイトルを使わず任意の文字にする
現在の投稿と同じカテゴリー内の次の投稿へのリンクを、テキストをカスタマイズして表示します。投稿タイトルは入れません。「Next post in category」というテキストはあなたの希望にあわせてカスタマイズできます。
<?php next_post_link( '%link', 'Next post in category', TRUE ); ?>
同じカテゴリー内だが特定のカテゴリーを除外する
13 番(カテゴリー ID の数値)のカテゴリーだけを除外して、同じカテゴリーの次の投稿へのリンクを表示します。除外したいカテゴリーの番号は自由に変えられます。複数のカテゴリーを除外するには「,」で区切ってください。
<?php next_post_link( '%link', 'Next post in category', TRUE, '13' ); ?>
同じタクソノミー内
同じタクソノミー・ターム内の次の投稿へのリンクを表示します。投稿フォーマットはタクソノミーのひとつなので、下記の例は同じ投稿フォーマットの次の投稿へリンクします。
<?php next_post_link( '%link', 'Next post in taxonomy', TRUE, ' ', 'post_format' ); ?>
外部リソース
- Digging into Wordpress - Definitive Guide to WordPress Page Navigation
- Forum discussion on using a image with next_post_link
変更履歴
1.5.0 : 新規導入
ソースファイル
next_post_link() は wp-includes/link-template.php
にあります。
関連項目
ページネーション: posts_nav_link(), next_posts_link(), previous_posts_link(), get_next_posts_link(), get_previous_posts_link(), paginate_links(), wp_link_pages(), next_post_link(), previous_post_link(), next_image_link(), previous_image_link(), the_posts_pagination(), get_the_posts_pagination()
最新英語版: WordPress Codex » Function Reference/next_post_link (最新版との差分)