如何在没有收到评论的情况下调用我的自定义WordPress评论表单?

时间:2020-04-16 作者:Naser.Sadeghi

我刚刚创建了一条评论。php文件在我的WordPress主题文件夹中,我自定义了一些字段。我的主要目的是使用Bootstrap 4的输入组。当我使用下面的代码段调用注释时,一切正常:

 <?php
     if (comments_open()) :
         comments_template();
     else :
         echo \'<p>You cannot send comments for this post.</p>\';
     endif; 
  ?>
但在我网站的另一部分,我需要WordPresscomment_form() 在Bootstrap 4模式中。当我打电话给comment_form() 在那里,我得到的是WordPress的原始评论,而不是我自己创建(或者更好地说是修改)的表单。

这是我的代码:

<div class="modal fade" id="commenting">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <!-- Modal Header -->
            <div class="modal-header">
                <h4 class="modal-title">Post your comment</h4>
                <button type="button" class="close ml-0" data-dismiss="modal">&times;</button>
            </div>
            <!-- Modal body -->
            <?php 
               comment_form();
            ?>
            <!-- Modal footer -->
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-dismiss="modal">Cancel</button>
            </div>
         </div>
    </div>
</div>

1 个回复
SO网友:Sanjay Gupta

是的,您可以使用Bootstrap 4自定义注释表单。

您只需要对引导类和HTML进行一些编辑。

$args = array(
    \'comment_field\' => \'<p class="comment-form-comment"><label for="comment">\' . _x( \'Comment\', \'noun\' ) . \'</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>\'
  \'fields\' => apply_filters( \'comment_form_default_fields\', array(

    \'author\' =>
      \'<p class="comment-form-author">\' .
      \'<label for="author">\' . __( \'Name\', \'domainreference\' ) . \'</label> \' .
      ( $req ? \'<span class="required">*</span>\' : \'\' ) .
      \'<input id="author" name="author" type="text" value="\' . esc_attr( $commenter[\'comment_author\'] ) .
      \'" size="30"\' . $aria_req . \' /></p>\',

    \'email\' =>
      \'<p class="comment-form-email"><label for="email">\' . __( \'Email\', \'domainreference\' ) . \'</label> \' .
      ( $req ? \'<span class="required">*</span>\' : \'\' ) .
      \'<input id="email" name="email" type="text" value="\' . esc_attr(  $commenter[\'comment_author_email\'] ) .
      \'" size="30"\' . $aria_req . \' /></p>\',

    \'url\' =>
      \'<p class="comment-form-url"><label for="url">\' .
      __( \'Website\', \'domainreference\' ) . \'</label>\' .
      \'<input id="url" name="url" type="text" value="\' . esc_attr( $commenter[\'comment_author_url\'] ) .
      \'" size="30" /></p>\'
    )

);
comment_form( $args );
请用这个。我认为这会有帮助。

相关推荐

为什么COMMENTS_TEMPLATE()在没有Comments.php文件的情况下可以工作?

我想能够风格的评论部分,以配合我的主题建设。我没有意见。网站中的php文件,但当我包括:<?php if ( comments_open() || get_comments_number() ) : comments_template(); endif; ?> 我在我的帖子下面有一个完整的评论部分,可以添加和查看评论和评论信息。我想,当我加入上面的if语句时,应该是从评论中提取信息。包含所有html的php文件