【问题标题】:Edit Wordpress comment form (just add a class to the text inputs)编辑 Wordpress 评论表单(只需在文本输入中添加一个类)
【发布时间】:2010-07-26 14:46:11
【问题描述】:

我正在使用最新 Wordpress 附带的默认 20_10 主题并对其进行修改。我只想为新评论表单中的某些文本输入添加一个类(特别是添加

class="text"
使其与 Blueprint CSS 框架配合使用)。

我找不到执行此操作的位置。不熟悉 PHP,但在大多数情况下都能以我的方式解决它 - 只是似乎无法在此处找到表单。

任何帮助表示赞赏。

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    评论表单由 WordPress comment_form() 函数输出。要将 CSS 类添加到特定输入,您可以在从 TwentyTen cmets.php 文件底部调用时更改 $fields 参数。

    在下面的示例中,我在作者输入字段中添加了class="text"

    <?php
        $fields =  array(
            'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) . '<input class="text" 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' ) . '</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' ) . '</label>' . '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
        ); 
    
        comment_form(array('fields'=>$fields));
    
    ?>
    

    或者,您可以在主题的 functions.php 中创建一个过滤器,为您添加输入类:

    function my_comment_fields($fields) {
        foreach($fields as $field){
             // Add the class to your field's input
        }
        return $fields;
    }
    add_filter('comment_form_default_fields','my_comment_fields');
    

    【讨论】:

      【解决方案2】:

      登录到您的控制面板。 从文件管理器打开 wp-includes 文件夹。 选择comment-template.php 并单击编辑。 转到第 1541 行或搜索“”在此附近,您可以看到“您的电子邮件地址将不会被发布。必填字段标有 *”

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

      在 aTechguide.com http://atechguide.com/edit-comment-form-wordpress了解更多信息

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-02-10
        • 2022-07-05
        • 2011-08-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多