css - WordPress 中的自定义评论表单

标签 css wordpress comments

我想自定义 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 );
?>

这是结果:

Custom comment form

现在,我想为提交按钮添加两个 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/

相关文章:

wordpress - 页面搜索功能导致 SEO 的重复页面

python - 使用 praw 解析评论时遇到问题

html - 在 Opera 和 Chrome 的新标签页中打开来自 iframe 的链接

css - 页脚在页面中间

php - 在 wordpress 中选择查询

php - wp_generate_attachment_metadata 返回一个空数组

r - 防止 R Studio 收到 'skipping' 注释。运行每行

Python:我在函数下的注释的最后 3 个引号 'indented block' ") 中收到 (""错误。怎么了?

css - 为什么有 std::vector 的迭代器

javascript - 在表内加载另一个组件会意外地在Angular中扩展我的表宽度