我把自己的主题发展成了《二十一世纪》的变体。
我在努力避免aria-required
由注释模板打印。为了便于维护,我宁愿在自己的主题中覆盖注释模板,也不愿更改当前正在调用的模板。
如何在我自己的主题中覆盖注释模板?
我把自己的主题发展成了《二十一世纪》的变体。
我在努力避免aria-required
由注释模板打印。为了便于维护,我宁愿在自己的主题中覆盖注释模板,也不愿更改当前正在调用的模板。
如何在我自己的主题中覆盖注释模板?
我不知道您为什么要删除aria-required
属性它是W3草案中的一个表单属性,处理与应用程序和残疾用户一起工作的可访问性。
无论如何,您可以通过过滤comment_form_default_fields
和comment_form_field_comment
. 下面的示例可以用作插件或主题的functions.php
文件,并将删除aria-required
属性
/* Attach the custom_comment_form_fields() function to the comment_form_default_fields hook. */
add_filter( \'comment_form_default_fields\', \'custom_comment_form_fields\' );
/* Attach the custom_comment_form_field_comment() function to the comment_form_field_comment hook. */
add_filter( \'comment_form_field_comment\', \'custom_comment_form_field_comment\' );
/**
* Remove the aria-reuqired from name and email comment fields.
*/
function custom_comment_form_fields() {
/* Get current commenter. */
$commenter = wp_get_current_commenter();
/* Check if name and email fields are required. */
$req = get_option( \'require_name_email\' );
/* Remove the aria-required attribute. */
$fields = array(
\'author\' => \'<p class="comment-form-author">\' . \'<label for="author">\' . __( \'Name\' ) . \'</label> \' . ( $req ? \'<span class="required">*</span>\' : \'\' ) .
\'<input id="author" name="author" type="text" value="\' . esc_attr( $commenter[\'comment_author\'] ) . \'" size="30" /></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" /></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>\'
);
return $fields;
}
/**
* Remove the aria-reuqired from comment textarea field.
*/
function custom_comment_form_field_comment() {
/* Comment text area. */
$textarea = \'<p class="comment-form-comment"><label for="comment">\' . _x( \'Comment\', \'noun\' ) . \'</label><textarea id="comment" name="comment" cols="45" rows="8"></textarea></p>\';
return $textarea;
}
我需要显示从第二个开始的注释,省略第一个。对于帖子,我使用了“offset”,但我找不到任何类似的评论。由于我使用的是线程注释,因此必须从第二条非子注释(仅父注释)开始。我正在使用带有回调的wp\\u list\\u注释。编辑2:这是实际的评论。php代码,回复后: <?php $i = 2; if ( have_comments() ) : if ( $i > 1 ) : ?> <div id=\"comments\"