万が一、当サイトで重大な問題を発見した際などは、フォーラムや WordSlack #docs チャンネルでお知らせください。</p>
テンプレートタグ/comments popup link
目次
説明
comments_popup_script() が使用されている場合はコメントポップアップウィンドウへのリンクを、そうでない場合は通常のリンクを表示します。ループ あるいはコメントループの中で記述する必要があります。
使い方
<?php comments_popup_link( $zero, $one, $more, $css_class, $none ); ?>
パラメータ
- $zero
- (文字列) (オプション) コメント数が 0 の場合に出力するテキスト。
- 初期値: 'No Comments'
- $one
- (文字列) (オプション) コメント数が 1 つの場合に出力するテキスト
- 初期値: '1 Comment'
- $more
- (文字列) (オプション) コメント数が 2 つ以上の場合に出力するテキスト。% 記号が実際の数と置き換えられる(% so far が 5 so far になる)。
- 初期値: '% Comments'
- $css_class
- (文字列) (オプション) a要素に追加するCSSクラス。デフォルト値は無。
- 初期値: なし
- $none
- (文字列) (オプション) コメントを受け付けていない場合に出力するテキスト。
- 初期値: 'Comments Off'
用例
コメント数に対する応答
コメントが無い場合に "No comments yet" を、1件の場合には"1 comment"、それ以上の場合に "% comments" for more than one (% replaced by # of comments),を表示し、コメントが無効になっている場合には "Comments are off for this post" を表示します。さらに、カスタム CSS リンクとして 'comments-link' を追加します。
<p> <?php comments_popup_link( 'No comments yet', '1 comment', '% comments', 'comments-link', 'Comments are off for this post'); ?> </p>
コメントが無効になっているときにリンクを隠す
投稿画面でコメントが無効になっているときに comments_popup_link を含む段落要素 <p></p> を隠します。投稿毎にコメントを有効/無効にする場合に便利です。ループ内で使用してください。
<?php if ( comments_open() ) : echo '<p>'; comments_popup_link( 'No comments yet', '1 comment', '% comments', 'comments-link', 'Comments are off for this post'); echo '</p>'; endif; ?>
コメントの条件に応じて異なるCSSクラスを読み込む
If you want to load different classes into comments_popup_link(), use the following:
$css_class = 'zero-comments'; $number = (int) get_comments_number( get_the_ID() ); if ( 1 === $number ) $css_class = 'one-comment'; elseif ( 1 < $number ) $css_class = 'multiple-comments'; comments_popup_link( __( 'Post a Comment', 'your-theme' ), __( '1 Comment', 'your-theme' ), __( '% Comments', 'your-theme' ), $css_class, __( 'Comments are Closed', 'your-theme' ) );
ソースファイル
comments_popup_link() は wp-includes/comment-template.php
にあります。
関連資料
コメント関数: cancel_comment_reply_link(), comment_author(), comment_author_email(), comment_author_email_link(), comment_author_IP(), comment_author_link(), comment_author_rss(), comment_author_url(), comment_author_url_link(), comment_class(), comment_date(), comment_excerpt(), comment_form_title(), comment_form(), comment_ID(), comment_id_fields() / en, comment_reply_link(), comment_text(), comment_text_rss(), comment_time(), comment_type(), comments_link, comments_number(), comments_open(), comments_popup_link(), comments_popup_script(), comments_rss_link(), get_avatar(), next_comments_link(), paginate_comments_links(), permalink_comments_rss(), previous_comments_link(), wp_list_comments()
最新英語版: WordPress Codex » Template Tags/comments_popup_link (最新版との差分)
fax:Function_Reference/comments_popup_link