WordPressにコメント欄を付ける

WordPressでオリジナルのテーマを作った際などに、投稿ページにコメント欄をつける方法です。

コメント欄を表示させたい場所のファイル(single.phpなど)のコメント欄を置きたい場所へ下記を記入します。

<?php comments_template(); ?>

このタグを記入する事によりテーマ内の”comments.php”ファイルの読み込みができます。もし”comments.php”ファイルがなくても、デフォルトでwordpressに入っている wp-includes内のtheme-compatファイルのcomments.phpを読み込んでコメント欄を表示してくれます。

参照:Codex|インクルードタグ
   Include Tags

デフォルトのhtml文。
↓このコードが生成される

<div id="respond">
<h3>コメントをどうぞ</h3>
<div id="cancel-comment-reply">
	<small><a rel="nofollow" id="cancel-comment-reply-link" href="/wordpress/?p=1796#respond" style="display:none;">返信をキャンセル</a></small>
</div>
<form action="http://localhost/wordpress/wp-comments-post.php" method="post" id="commentform">
<p><input type="text" name="author" id="author" value="" size="22" tabindex="1" aria-required="true">
<label for="author"><small>名前  (必須) </small></label></p>
<p><input type="text" name="email" id="email" value="" size="22" tabindex="2" aria-required="true">
<label for="email"><small>メールアドレス (非公開)  (必須) </small></label></p>
<p><input type="text" name="url" id="url" value="" size="22" tabindex="3">
<label for="url"><small>ウェブサイト</small></label></p>
 <!--<p><small><strong>XHTML:</strong> 次のタグを使用できます: <code>&lt;a href=&quot;&quot; title=&quot;&quot;&gt; &lt;abbr title=&quot;&quot;&gt; &lt;acronym title=&quot;&quot;&gt; &lt;b&gt; &lt;blockquote cite=&quot;&quot;&gt; &lt;cite&gt; &lt;code&gt; &lt;del datetime=&quot;&quot;&gt; &lt;em&gt; &lt;i&gt; &lt;q cite=&quot;&quot;&gt; &lt;strike&gt; &lt;strong&gt; </code></small></p>-->
<p><textarea name="comment" id="comment" cols="58" rows="10" tabindex="4"></textarea></p>
<p><input name="submit" type="submit" id="submit" tabindex="5" value="コメントを送信">
<input type="hidden" name="comment_post_ID" value="1796" id="comment_post_ID">
<input type="hidden" name="comment_parent" id="comment_parent" value="0">
</p>
</form>
</div>

ブラウザで見るとこんな感じです。
コメント欄表示例

Related Article

5 Comments & Tracbacks

  • admin 2012-03-23 9:22 AM

    何かのお役に立てば幸いです^ー^

    Reply

  • チャーリー 2013-04-11 4:59 AM

    こんにちは。
    僕の場合、カテゴリーにコメントを表示したいのですが、
    <?php comments~
    を挿入してもコメント欄が表示されません。
    どうしたらいいか分かりませんか?

    Reply

    • saori 2013-04-11 6:59 PM

      チャーリー さんへ

      うーん…ソースを見てないのでなんとも言えませんが、ループの外に書いているとかはないですか?

      Reply

  • saori 2015-05-03 11:17 AM

    yuriyurib さま

    こんにちは。ディスカッションの設定でしょうかね…??以下のページを参考に、コメントが有効化されているか確認されてみてはいかがでしょうか。
    ◆ コメントを有効化・無効化する — サポート — WordPress.com
    もしくは、以下のページの方のように、テンプレートタグを記入する位置が間違っているとかはないですか?
    ◆ WordPress › フォーラム » 固定ページにコメント欄を表示させたいです。

    Reply

  • saori 2015-05-05 2:39 PM

    yuriyurib さま
    いえいえー。お役に立てて光栄です。

    Reply

Leave a Comment

admin にコメントする コメントをキャンセル

Emailは公開されません。*は必須項目です。


*


Categorys

Tags

CSS3 ダッシュボード ヘッダー トラブル コードサンプル コンテンツ スライドショー jQueryプラグイン php 引っ越し 素材 お知らせ JavaScript Facebook CSS カテゴリー 投稿タイプ IE HTML5 Shareボタン seo レスポンシブ Photoshop タクソノミー ナビゲーション カスタムメニュー Git Macアプリ サイドバー WPセキュリティ SVG iTunes PHPリファレンス API WP使い方 query_posts データベース get_posts() 条件分岐 コメント function RSS スマートフォン Sass/Compass さくらVPS