修改评论数显示文本

时间:2015-09-09 作者:Shahrukh Khan

如何将注释数的文本修改为自定义文本。

我当前的显示如下

enter image description here

我希望它像这样显示。

enter image description here

我的commpents.php

<?php
/**
 * The template for displaying Comments.
 *
 * The area of the page that contains both current comments
 * and the comment form.
 *
 */

/*
 * 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() ) {
    return;
}
?>

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

    <?php // You can start editing here -- including this comment! ?>

    <?php if ( have_comments() ) : ?>
        <h2 class="comments-title">
            <?php

                printf( _nx( \'One comment:\', \'%1$s Reviews:\', get_comments_number(), \'comments title\', \'simone\' ),
                    number_format_i18n( get_comments_number() )
                                );
            ?>
        </h2>

        <ol class="comment-list">
            <?php
                wp_list_comments( array(
                    \'style\'      => \'ol\',
                    \'short_ping\' => true,
                                        \'avatar_size\'=> 50,
                ) );
            ?>
        </ol><!-- .comment-list -->
        <?php if ( get_comment_pages_count() > 1 && get_option( \'page_comments\' ) ) : // are there comments to navigate through ?>
        <nav id="comment-nav-below" class="comment-navigation clear" role="navigation">
            <h1 class="screen-reader-text"><?php _e( \'Comment navigation\', \'simone\' ); ?></h1>
            <div class="nav-previous"><?php previous_comments_link( sprintf( \'<i class="fa fa-arrow-circle-o-left">%s</i> \', __( \'Older Comments\', \'simone\' ) ) ); ?></div>
            <div class="nav-next"><?php next_comments_link( sprintf( \'<i class="fa fa-arrow-circle-o-right">%s</i> \', __( \'Newer Comments\', \'simone\' ) ) ); ?></div>
        </nav><!-- #comment-nav-below -->
        <?php endif; // check for comment navigation ?>

    <?php endif; // 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 _e( \'Comments are closed.\', \'simone\' ); ?></p>
    <?php endif; ?>

    <?php comment_form(); ?>

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

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

更换

<?php
        printf( _nx( \'One comment:\', \'%1$s Reviews:\', get_comments_number(), \'comments title\', \'simone\' ),
           number_format_i18n( get_comments_number() )
                 );
?>
使用

<?php 
    do_action(\'my_comments_title_hook\');
?>
然后(自函数comments_template() 在循环中调用,您可以使用$post->ID ):

function change_coments_title() {

    if ( get_post_type() == \'post\' ) {
        printf( _nx( \'One comment:\', \'%1$s Comments:\', get_comments_number(), \'comments title\', \'simone\' ), number_format_i18n( get_comments_number() ) );
    } elseif ( get_post_type() == \'review\' ) {
        printf( _nx( \'One Review:\', \'%1$s Reviews:\', get_comments_number(), \'comments title\', \'simone\' ), number_format_i18n( get_comments_number() ) );
    } elseif ( get_post_type() == \'page\' ) {
        printf( _nx( \'One Review:\', \'%1$s Reviews:\', get_comments_number(), \'comments title\', \'simone\' ), number_format_i18n( get_comments_number() ) );
    }
    //Other post types
}
add_action( \'my_comments_title_hook\', \'change_coments_title\' );
上面的示例函数不会更改“posts”的任何内容,但如果您使用的是一个名为“reviews”的CPT,它会起到作用。如果你想为所有类型的帖子设置标题,一定要让我知道。

相关推荐

Admin Theme customization

我遵循wordpress codex网站上关于通过插件创建管理主题的说明。我激活了插件,但我的样式表没有包含在<head>.. 这是我的代码:add_action( \'admin_init\', \'kd_plugin_admin_init\' ); add_action( \'admin_menu\', \'kd_plugin_admin_menu\' ); function kd_plugin_admin_init() { /* Register