我想自定义 WordPress 中 comment_form()
函数的输出。
为了编辑字段和文本区域,我使用了以下代码,一切正常。
<?php
$req = get_option( 'require_name_email' );
$fields = array(
// redefine author field
'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name:' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label>' .
'<div class="input-prepend"><span class="add-on"><i class="icon-user"></i></span><input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . 'aria-required="true"' . ' required /></p>',
'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email Address:' ) . ( $req ? ' <span class="required">*</span><br/>' : '' ) . '</label>' .
'<div class="input-prepend"><span class="add-on"><i class="icon-envelope"></i></span><input required id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . 'aria-required="true"' . ' required /></div></p>',
'url' => '<p class="comment-form-url"><label for="url">' . __( 'Your Website:' ) . '</label>' .
'<div class="input-prepend"><span class="add-on"><i class="icon-globe"></i></span><input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></div></p>'
);
$comments_args = array(
'fields' => $fields,
// redefine your own textarea (the comment body)
'comment_field' => '<p class="comment-form-comment"><label for="comment">' . 'Comment' . '</label><textarea id="comment" name="comment" class="span12" rows="5" aria-required="true"></textarea></p>',
);
comment_form( $comments_args );
?>
这是结果:
现在,我想为提交按钮添加两个 CSS 类 (class="btn btn-primary"
);不使用 jQuery 我怎样才能做到这一点?
注意:
有关解决方案,请阅读有关标有绿色符号的答案的评论。
最佳答案
正如 krizna 所说,您可以修改主题的 comments.php
文件来更改 comment_form()
的输出。我认为在这种情况下这可能是你最好的选择。
如果你看一下Function Reference对于 Codex 中的 comment_form()
,您会发现只能修改提交按钮的 ID,而不能修改类。 Trac 上有一些与此相关的票证:
如果在这种情况下修改 comments.php
对您不起作用,您可以尝试应用其中一个补丁。
关于css - WordPress 中的自定义评论表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14609311/