5

私は現在、独自のWordpressテーマを開発しており、最近カスタムに取り組んでいますcomments_template();。この方法を使用するwp_list_comments();ことが、ページ/投稿ごとにコメントを取得して表示するためのベストプラクティスであることを読みました。コメントがそのメソッドを介して取り込まれ、表示される方法を正常にカスタマイズしました。

comment_form();また、この方法を使用することがコメントフォームを表示するためのベストプラクティスであることも読みました。しかし、私はこれをカスタマイズしようと本当に苦労しています。$ argsfiltersactionsの間で少し混乱しています。

基本的に、コメントフォームの一部を大幅に変更したいと思います。comment_form();メソッドのベストプラクティスを使用しながら、コメントフォームの一部を変更するにはどうすればよいですか?

私が本当にする必要があるのは、既存の<p>タグのいくつかをでラップすることだけです<divs>。私が行おうとしている更新のリストは以下のとおりです。

  1. <h3>ヘッダーを微調整して<h2 class="comments-header">Tell us about you!</h2>
  2. フォームフィールドを<fieldset></fieldset>
  3. ラップ<label>イン<div class="label"></div>
  4. ラップ<input>イン<div class="field"></div>
  5. コメントの後ではなく<p class="form-allowed-tags"></p>表示する<textarea>
  6. フォームの送信ボタンを変更して、<button>要素ではなく要素を使用する<input>

詳細な説明については、以下のコードを参照してください...

デフォルトのcomment_form(); 出力されるコード:

<div id="respond">
    <h3 id="reply-title">Leave a Reply</h3>
    <form action="http://localhost/.../wp-comments-post.php" method="post" id="commentform">
        <p class="comment-notes">
            Your email address will not be published. Required fields are marked
            <span class="required">*</span>
        </p>
        <p class="comment-form-author">
            <label for="author">Name</label>
            <span class="required">*</span>
            <input id="author" name="author" type="text" value="John Doe" size="30" aria-required="true">
        </p>
        <p class="comment-form-email">
            <label for="email">Email</label>
            <span class="required">*</span>
            <input id="email" name="email" type="text" value="johndoe@dodgeit.com" size="30" aria-required="true">
        </p>
        <p class="comment-form-url">
            <label for="url">Website</label>
            <input id="url" name="url" type="text" value size="30">
        </p>
        <p class="comment-form-comment">
            <label for="comment">Comment</label>
            <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea>
        </p>
        <p class="form-allowed-tags">
            You may use these HTML tags and attributes...
        </p>
        <p class="form-submit">
            <input name="submit" type="submit" id="submit" value="Post Comment">
            <input type="hidden" name="comment_post_ID" value="22" id="comment_post_ID">
            <input type="hidden" name="comment_parent" id="comment_parent" value="0">
        </p>
    </form>
</div> <!-- #respond -->

私が出力しようとしているコード:

<div id="respond">
    <h2 class="comments-header">Tell us about you!</h2>
    <form action="http://localhost/.../wp-comments-post.php" method="post" id="commentform">
        <fieldset>
            <div class="label"><label for="author">Name <span class="required">*</span></label></div>
            <div class="field"><input id="author" name="author" type="text" value="<?php echo $comment_author_email; ?>" size="30" aria-required="true"></div>
        </fieldset>
        <fieldset>
            <div class="label"><label for="email">E&ndash;mail (will not be published) <span class="required">*</span></label></div>
            <div class="field"><input id="email" name="email" type="text" value="<?php echo $comment_author_email; ?>" size="30" aria-required="true"></div>
        </fieldset>

        <p class="form-allowed-tags">
            You may use these HTML tags and attributes...
        </p>

        <fieldset>
            <div class="field"><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></div>
        </fieldset>

        <p class="form-submit">
            <button class="story-submit-btn" type="submit" name="submit" id="sub">Post your story</button>
            <input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" id="comment_post_ID">
            <input type="hidden" name="comment_parent" id="comment_parent" value="0">
        </p>
    </form>
</div> <!-- #respond -->

どんな助けでも大歓迎です!

4

8 に答える 8

4

他のすべてが失敗した場合は、テーマ ディレクトリの comments.php を次のように変更comment_form($args);します。

ob_start();
comment_form($args);
$comment_form = ob_get_clean();
//insert code to modify $comment_form
echo $comment_form;

これを使用して、送信ボタンを画像ボタンに変更しました。

于 2012-11-30T21:16:12.213 に答える
3

functions.phpコメントの表示を変更するために使用します。それが現在のやり方であるかどうかはわかりません(私がWPで開発していた最後のサイトで、コメントが必要だったのは2009年でした;))が、ここにあります(functions.phpファイルに配置してください!:

function THEMENAME_comment($comment, $args, $depth) {
  $GLOBALS['comment'] = $comment;
  *your comment display code*
}

ピンバック テーマも忘れずに作成してください。コメントと同様に行いますが、違いは最初の行だけです。

関数 THEMENAME_pings($comment, $args, $depth)

他の方法はcomments_templateを使用している可能性があります。

于 2012-07-07T21:59:20.797 に答える
3

コンテンツを投稿した後のSingle.php

カスタム コメント フォームの HTML とデザインに使用します

    <?php $comments_args = array(
        // change the title of send button 
        'label_submit'=>'Submit',
        // change the title of the reply section
        'title_reply'=>'Add a comment',
        // remove "Text or HTML to be displayed after the set of comment fields"
        'comment_form_top' => 'ds',
        'comment_notes_before' => '',
        'comment_notes_after' => '',
        // redefine your own textarea (the comment body)
        'comment_field' => '<p class="comment-form-comment"><textarea id="comment" name="comment" placeholder="Your Comment* " aria-required="true"></textarea></p>',
        'fields' => apply_filters( 'comment_form_default_fields', array(

    'author' =>
      '<p class="comment-form-author">'  .
      '<input id="author" class="blog-form-input" placeholder="Your Name* " name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) .
      '" size="30"' . $aria_req . ' /></p>',

    'email' =>
      '<p class="comment-form-email">'.
      '<input id="email" class="blog-form-input" placeholder="Your Email Address* " name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) .
      '" size="30"' . $aria_req . ' /></p>',

    'url' =>
      '<p class="comment-form-url">'.
      '<input id="url" class="blog-form-input" placeholder="Your Website URL" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) .
      '" size="30" /></p>'
    )
  ),
);

comment_form($comments_args);?>
于 2014-09-16T08:07:14.770 に答える
1

コーデックスを確認しましたか:http://codex.wordpress.org/Function_Reference/comment_form

カスタマイズするのは簡単ではありませんが、実行可能です

于 2012-07-04T20:04:56.390 に答える
0

私のテーマはデフォルトの関数 comment_form を使用していたので、子テーマに変更を加えました。

    if(function_exists('glutton_comment_form'))
        glutton_comment_form(); //custom function for displaying comments, defined in glutton-child/functions.php
    else
        comment_form();
于 2018-01-02T07:47:11.773 に答える