COMMENT_Form()不更改元素的默认类/ID

时间:2017-05-04 作者:Frederick M. Rogers

EDIT 我正在尝试更改<form> 元素以及<input>/使用提交按钮字段comment_form() 作用不管怎样,各种字符串值都会被回显,而不是替换默认值(请参见演示链接)。

CODE:

<?php if ( comments_open() ) : ?>

    <?php
        $req = get_option( \'require_name_email\' );
        $aria_req = ( $req ? \' aria-required="true"\' : \'\' );

        $fields = array(
            \'id_form\'       => \'comment-form\',
            \'class_form\'    => \'form-inline\',
            \'class_submit\'  => \'btn btn-default\',
            \'author\'        => \'<div class="form-group">
                                <label for="comment-author" class="sr-only">\' . __( \'Author\', \'magneton\' ) . \'</label>
                                <input type="text" name="author" id="comment-author" class="form-control" placeholder="\' . __( \'Author (required)\', \'magneton\' ) . \'"\' . $aria_req . \'>\',
            \'email\'         => \'<label for="comment-author-email" class="sr-only">\' . __( \'E-Mail\', \'magneton\' ) . \'</label>
                                <input type="email" name="email" id="comment-author-email" class="form-control" placeholder="\' . __( \'E-Mail (required)\', \'magneton\' ) . \'"\' . $aria_req . \'>\',
            \'url\'            => \'<label for="comment-author-url" class="sr-only">\' . __( \'Website\', \'magneton\' ) . \'</label>
                                <input type="url" name="url" id="comment-author-url" class="form-control" placeholder="\' . __( \'Website\'. \'magneton\' ) . \'">
                                </div>\'
        );

        $comments_args = array(
            \'fields\' => $fields,
            \'title_reply\' => __( \'Leave a reply\', \'magneton\' ),
            \'comment_field\' => \'<textarea name="comment" id="comment" class="form-control"  aria-required="true" rows="10"></textarea>\',
            \'label_submit\' => __( \'Submit Comment\', \'magneton\' )
        );
    ?>

    <?php comment_form( $comments_args ); ?> 

<?php endif; ?>
LINK: DEMO

1 个回复
最合适的回答,由SO网友:Dave Romsey 整理而成

这些类正在内联呈现,因为id_form, class_form, 和class_submit 参数应放置在$comments_args 阵列(旁边title_reply, comment_field, etc)且不在$fields 大堆看见comment_form().

还有最后一个问题,有没有办法重新安排字段的顺序?

可以,字段可以重新排序。Here\'s an answer that shows how to accomplish reordering and customizing the comment fields. 对注释字段进行重新排序的主要问题是,如果希望主注释字段显示在名称/电子邮件/URL/等字段上方,则comment_form_defaults 需要使用筛选器来设置$comment_field 到空字符串。这是因为参数是如何设置的;$comment_field 是特殊的,不是$fields 默认情况下为数组。以上链接的答案涵盖了这一点。

相关推荐