WordPress注册用户的自定义评论表单

时间:2017-10-23 18:22:14

标签: wordpress forms comments

我想用两个字段修改默认评论表单:“评论”和“名称”。

然后我需要在页面上的评论列表中显示“名称”。

我只需要注册或登录用户。我不想出现用户名。我需要“名称”字段的内容。

我该怎么做?

最佳。

1 个答案:

答案 0 :(得分:1)

现在有很多关于你在互联网上需要什么的文章。只需谷歌“wordpress评论模板”或其他短语。 但是为了给您提供一种存档更改的可能方式:

编辑评论表:

通常,评论表单旁边的评论表单中有“author”,“email”和“url”字段。在 functions.php 中使用过滤器“comment_form_default_fields”时,可以更改输入字段的默认显示,并禁用未使用的字段“email”和“url”。

所以只需在 functions.php 中编写自己的函数,然后将其添加到过滤器中,如下所示:

function your_comment_form_fields($fields){
    $fields['email'] = '';  //remove default email input
    $fields['url'] = '';  //remove default url input
    return $fields;
}

add_filter('comment_form_default_fields','your_comment_form_fields');

这将在全球范围内发挥作用。

编辑可以查看评论的人:

限制能够看到您需要的注释的用户覆盖模板中的默认comments.php。只需在主题文件夹中创建 comments.php 即可。例如,我使用WordPress Codex中的comments默认示例,并在处理显示注释内容的部分之前添加if语句。如果is_user_logged_in()函数未返回true,则不显示任何内容。您还可以进一步更改评论模板的其他部分。

<?php
/**
 * The template for displaying Comments.
 *
 * The area of the page that contains comments and the comment form.
 *
 * @package WordPress
 * @subpackage Twenty_Thirteen
 * @since Twenty Thirteen 1.0
 */

/*
 * If the current post is protected by a password and the visitor has not yet
 * entered the password we will return early without loading the comments.
 */
if ( post_password_required() || !is_user_logged_in() )
    return;
?>

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

    <?php if ( have_comments() ) : ?>
        <h2 class="comments-title">
            <?php
            printf( _nx( 'One thought on "%2$s"', '%1$s thoughts on "%2$s"', get_comments_number(), 'comments title', 'twentythirteen' ),
                number_format_i18n( get_comments_number() ), '<span>' . get_the_title() . '</span>' );
            ?>
        </h2>

        <ol class="comment-list">
            <?php
            wp_list_comments( array(
                'style'       => 'ol',
                'short_ping'  => true,
                'avatar_size' => 74,
            ) );
            ?>
        </ol><!-- .comment-list -->

        <?php
        // Are there comments to navigate through?
        if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) :
            ?>
            <nav class="navigation comment-navigation" role="navigation">
                <h1 class="screen-reader-text section-heading"><?php _e( 'Comment navigation', 'twentythirteen' ); ?></h1>
                <div class="nav-previous"><?php previous_comments_link( __( '&larr; Older Comments', 'twentythirteen' ) ); ?></div>
                <div class="nav-next"><?php next_comments_link( __( 'Newer Comments &rarr;', 'twentythirteen' ) ); ?></div>
            </nav><!-- .comment-navigation -->
        <?php endif; // Check for comment navigation ?>

        <?php if ( ! comments_open() && get_comments_number() ) : ?>
            <p class="no-comments"><?php _e( 'Comments are closed.' , 'twentythirteen' ); ?></p>
        <?php endif; ?>

    <?php endif; // have_comments() ?>

    <?php comment_form(); ?>

</div><!-- #comments -->