如何在评论字段上添加div/已编辑

时间:2016-08-29 作者:CodeAlb

如何将作者、电子邮件、Url等评论表单放入div。。

我正在使用args,但这对我不起作用

<?php
    if ( post_password_required() ) {
        return;
    }
?>

<div id="comments" class="comments-area">

    <?php // You can start editing here ?>

    <?php if ( have_comments() ) : ?>
        <h2 class="comments-title">
            <?php
                printf( // WPCS: XSS OK.
                    esc_html( _nx( \'One comment on &ldquo;%2$s&rdquo;\', \'%1$s comments on &ldquo;%2$s&rdquo;\', get_comments_number(), \'comments title\', \'nuvola\' ) ),
                    number_format_i18n( get_comments_number() ),
                    \'<span>\' . get_the_title() . \'</span>\'
                );
            ?>
        </h2>

        <?php if ( get_comment_pages_count() > 1 && get_option( \'page_comments\' ) ) : // Are there comments to navigate through? ?>
        <nav id="comment-nav-above" class="navigation comment-navigation" role="navigation">
            <h2 class="screen-reader-text"><?php esc_html_e( \'Comment navigation\', \'nuvola\' ); ?></h2>
            <div class="nav-links">

                <div class="nav-previous"><?php previous_comments_link( esc_html__( \'Older Comments\', \'nuvola\' ) ); ?></div>
                <div class="nav-next"><?php next_comments_link( esc_html__( \'Newer Comments\', \'nuvola\' ) ); ?></div>

            </div><!-- .nav-links -->
        </nav><!-- #comment-nav-above -->
        <?php endif; // Check for comment navigation. ?>

        <ol class="commentlist">
            <?php wp_list_comments(\'type=comment&callback=nuvola_comments\'); ?>
        </ol>

        <?php if ( get_comment_pages_count() > 1 && get_option( \'page_comments\' ) ) : // Are there comments to navigate through? ?>
        <nav id="comment-nav-below" class="navigation comment-navigation" role="navigation">
            <h2 class="screen-reader-text"><?php esc_html_e( \'Comment navigation\', \'nuvola\' ); ?></h2>
            <div class="nav-links">

                <div class="nav-previous"><?php previous_comments_link( esc_html__( \'Older Comments\', \'nuvola\' ) ); ?></div>
                <div class="nav-next"><?php next_comments_link( esc_html__( \'Newer Comments\', \'nuvola\' ) ); ?></div>

            </div><!-- .nav-links -->
        </nav><!-- #comment-nav-below -->
        <?php endif; // Check for comment navigation. ?>

    <?php endif; // Check for have_comments(). ?>

    <?php
        // If comments are closed and there are comments, let\'s leave a little note, shall we?
        if ( ! comments_open() && \'0\' != get_comments_number() && post_type_supports( get_post_type(), \'comments\' ) ) :
    ?>
        <p class="no-comments"><?php esc_html_e( \'Comments are closed.\', \'nuvola\' ); ?></p>
    <?php endif; ?>
        <?php $args = array(
-----------------------------------------------
      \'author\' =>
    \'<p class="comment-form-author"><label for="author">\' . __( \'Name\', \'domainreference\' ) . \'</label> \' .
    ( $req ? \'<span class="required">*</span>\' : \'\' ) .
    \'<input 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\', \'domainreference\' ) . \'</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\', \'domainreference\' ) . \'</label>\' .
    \'<input id="url" name="url" type="text" value="\' . esc_attr( $commenter[\'comment_author_url\'] ) .
    \'" size="30" /></p>\',
-----------------------------------------------
        );?>
    <?php comment_form( $args ); ?>

</div><!-- #comments -->
我试着\'Author\' => \'<div>..code..\' 并在关闭div\'url\' => \'..code.. </div>\' 但它不起作用。我所做的每一项更改,而不是预览。。我做错了?

1 个回复
最合适的回答,由SO网友:Greg McMullen 整理而成

这个comment_form() 在加载您的参数时不太正确。

你需要进去\'fields\' => apply_filters( \'comment_form_default_fields\', $fields ), 进入一个新的论点。附件是您需要更新的示例。

要填写的字段

$fields =  array(
  \'author\' =>
    \'<div class="comment-form-author"><label for="author">\' . __( \'Name\', \'domainreference\' ) . \'</label> \' .
    ( $req ? \'<span class="required">*</span>\' : \'\' ) .
    \'<input id="author" name="author" type="text" value="\' . esc_attr( $commenter[\'comment_author\'] ) .
    \'" size="30"\' . $aria_req . \' /></div>\',
  \'email\' =>
    \'<div class="comment-form-email"><label for="email">\' . __( \'Email\', \'domainreference\' ) . \'</label> \' .
    ( $req ? \'<span class="required">*</span>\' : \'\' ) .
    \'<input id="email" name="email" type="text" value="\' . esc_attr(  $commenter[\'comment_author_email\'] ) .
    \'" size="30"\' . $aria_req . \' /></div>\',

  \'url\' =>
    \'<div class="comment-form-url"><label for="url">\' . __( \'Website\', \'domainreference\' ) . \'</label>\' .
    \'<input id="url" name="url" type="text" value="\' . esc_attr( $commenter[\'comment_author_url\'] ) .
    \'" size="30" /></div>\',
);
注释表单参数
$comments_args = array(
    // change the title of send button 
    \'label_submit\'=>\'Send\',
    // change the title of the reply section
    \'title_reply\'=>\'Write a Reply or Comment\',
    // remove "Text or HTML to be displayed after the set of comment fields"
    \'comment_notes_after\' => \'\',
    // redefine your own textarea (the comment body)
    \'comment_field\' => \'<div class="comment-form-comment"><label for="comment">\' . _x( \'Comment\', \'noun\' ) . \'</label><br /><textarea id="comment" name="comment" aria-required="true"></textarea></div>\',
    \'fields\' => apply_filters( \'comment_form_default_fields\', $fields ),
);

comment_form($comments_args);
唯一值得注意的是\'fields\' => apply_filters( \'comment_form_default_fields\', $fields$comment_args. 这将允许您传入更新表单字段。

相关推荐

评论表单代码重定向到带有空白页的wp_Comments_post.php

单个帖子中的评论形式效果很好。然后,在添加一些定制之后,在发布评论之后,它会重定向到此链接wp\\u comments\\u post。带有空白页的php。这是我在注释中的代码。php那么,让它再次工作到底出了什么问题?<?php $form_args = array( \'fields\' => array( \'author\' => \' <form class="getin_form" id="p