使用WordPress comment_form()无法回显内容

时间:2017-04-28 04:31:59

标签: php wordpress function

我试图将comment_form()作为字符串回显,因此可以使用ajax请求返回它。

似乎无法弄明白。

以下是一些代码:

$response .= '
            <div class="modal fade" id="commentsModal" tabindex="-1" role="dialog" aria-labelledby="commentsModalLabel">
              <div class="modal-dialog" role="document">
                <div class="modal-content">
        ';
                $commenter = wp_get_current_commenter();
                $req = get_option( 'require_name_email' );
                $aria_req = ( $req ? " aria-required='true'" : '' );
                $fields =  array(
                    'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Your name' ) . '</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 address' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
                        '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /><br /><span>We\'ll only send you an email when someone has commented on your post.</span></p>',
                );

                $comments_args = array(
                    'fields' =>  $fields,
                    'title_reply'=>'Post a comment',
                    'label_submit' => 'Post comment'
                );

                $response .= comment_form($comments_args);
        $response .= '
                </div>
              </div>
            </div>
        ';

任何人都知道如何将评论表格作为字符串。

干杯

1 个答案:

答案 0 :(得分:1)

您也可以通过这种方式返回您的回复。

?>
 <div class="modal fade" id="commentsModal" tabindex="-1" role="dialog" aria-labelledby="commentsModalLabel">
              <div class="modal-dialog" role="document">
                <div class="modal-content">
        <?php
                $commenter = wp_get_current_commenter();
                $req = get_option( 'require_name_email' );
                $aria_req = ( $req ? " aria-required='true'" : '' );
                $fields =  array(
                    'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Your name' ) . '</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 address' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
                        '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /><br /><span>We\'ll only send you an email when someone has commented on your post.</span></p>',
                );

                $comments_args = array(
                    'fields' =>  $fields,
                    'title_reply'=>'Post a comment',
                    'label_submit' => 'Post comment'
                );
                comment_form($comments_args, $post_id);
?>


                </div>
              </div>
            </div>