M
M
Marig2021-09-17 12:14:27
WordPress
Marig, 2021-09-17 12:14:27

How to put comments in your wordpress template?

Good afternoon!

Can you please tell me how to place a form for submitting comments and the comments themselves on the wordpress page? So that it all works as expected: you can add comments and show them on the page. The template is yours - written from scratch.

For some reason I can't. Apparently, all the same, there is not enough either knowledge or brains ...

<div id="dom_comment">
  <div class="row">
    <div class="col-md-12">
      <section>
        <h2>Комментарии</h2>
          <?php
            $comments = get_comments();
            $args = array( 'class' => 'mr-3');
            foreach ($comments as $comment){ 
          ?>
          <div class="media mb-3">
            <?php echo get_avatar($comment->author_email, 64, null, null, $args); ?>
            <div class="media-body">
              <h5 class="mt-0"><?php echo $comment->author; ?></h5>
              <?php echo $comment->comment_content ?>
            </div>
          </div>
          <?php } ?>
          <hr>
          <?php 
            $args = array(
              'fields' => array(
                'author' => '<div class="form-group row">
                  <label for="inputName" class="col-sm-2 col-form-label">' . __( 'Ваше имя' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label>
                  <div class="col-sm-10">
                    <input id="inputName" class="form-control" name="inputName" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . $html_req . ' />
                  </div>
                </div>',
                
                'email'  => '<div class="form-group row">
                  <label for="inputEmail" class="col-sm-2 col-form-label">' . __( 'Ваш email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label>
                  <div class="col-sm-10">
                    <input class="form-control" id="inputEmail" name="inputEmail" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30" aria-describedby="email-notes"' . $aria_req . $html_req  . ' />
                  </div>
                </div>',
                
                '<div class="form-group"> 
                  <textarea textarea class="form-control" id="inputMess" rows="3" name="comment" rows="8" aria-required="true"></textarea>
                </div>'
              )
            );
            
            add_filter('comment_form_fields', 'domashovo_reorder_comment_fields' );
            
            function domashovo_reorder_comment_fields( $fields ){
              $new_fields = array(); 
              $myorder = array('author','email','url','comment');
              foreach( $myorder as $key ){
                $new_fields[ $key ] = $fields[ $key ];
                unset( $fields[ $key ] );
              }
              if( $fields )
                foreach( $fields as $key => $val )
                  $new_fields[ $key ] = $val;
              return $new_fields;
            }					
            comment_form();
          ?>
      </section>
    </div>
  </div>
</div>


I would be grateful if you tell me how to implement this in a "working form" so to speak.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question