我正在使用最新 Wordpress 附带的默认二十_十主题并对其进行修改。我只想在新评论表单中的某些文本输入中添加一个类(特别是添加
类=“文本”使其与 Blueprint CSS 框架配合使用)。
我找不到执行此操作的地方。不是 au fait 与 PHP,但在大多数情况下能够解决它 - 似乎无法在这里找到表单。
任何帮助表示赞赏。
评论表单由 WordPress comment_form()函数输出。要将 CSS 类添加到特定输入,您可以在$fields从 TwoTen comments.php 文件底部调用时更改参数。
在下面的示例中,我已添加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));
?>
Run Code Online (Sandbox Code Playgroud)
或者,您可以在主题的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');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3881 次 |
| 最近记录: |