1

我正在为 wordpress 使用 Origin 主题,并且正在尝试自定义帖子正上方的评论链接。现在它显示评论的数量和文本“评论”,但我只想显示数字(当没有评论时显示 0)。我在 shortcodes.php 的主题 > 库 > 函数文件夹中找到了相关代码。

我如何编辑它以仅显示没有“评论”文本的评论数量,例如。“1”而不是“1 条评论”?

这是当前的代码:

function hybrid_entry_comments_link_shortcode( $attr ) {

    $comments_link = '';
    $number = doubleval( get_comments_number() );
    $attr = shortcode_atts( array( 'zero' => __( 'Leave a comment', 'hybrid-core' ), 'one' => __( '%1$s comment', 'hybrid-core' ), 'more' => __( '%1$s comments', 'hybrid-core' ), 'css_class' => 'comments-link', 'none' => '', 'before' => '', 'after' => '' ), $attr );

    if ( 0 == $number && !comments_open() && !pings_open() ) {
        if ( $attr['none'] )
            $comments_link = '<span class="' . esc_attr( $attr['css_class'] ) . '">' . sprintf( $attr['none'], number_format_i18n( $number ) ) . '</span>';
    }
    elseif ( 0 == $number )
        $comments_link = '<a class="' . esc_attr( $attr['css_class'] ) . '" href="' . get_permalink() . '#respond" title="' . sprintf( esc_attr__( 'Comment on %1$s', 'hybrid-core' ), the_title_attribute( 'echo=0' ) ) . '">' . sprintf( $attr['zero'], number_format_i18n( $number ) ) . '</a>';
    elseif ( 1 == $number )
        $comments_link = '<a class="' . esc_attr( $attr['css_class'] ) . '" href="' . get_comments_link() . '" title="' . sprintf( esc_attr__( 'Comment on %1$s', 'hybrid-core' ), the_title_attribute( 'echo=0' ) ) . '">' . sprintf( $attr['one'], number_format_i18n( $number ) ) . '</a>';
    elseif ( 1 < $number )
        $comments_link = '<a class="' . esc_attr( $attr['css_class'] ) . '" href="' . get_comments_link() . '" title="' . sprintf( esc_attr__( 'Comment on %1$s', 'hybrid-core' ), the_title_attribute( 'echo=0' ) ) . '">' . sprintf( $attr['more'], number_format_i18n( $number ) ) . '</a>';

    if ( $comments_link )
        $comments_link = $attr['before'] . $comments_link . $attr['after'];

    return $comments_link;
}
4

1 回答 1

0

您只需要删除相关位中的“评论”或“评论”一词。

有问题的行以$attr = shortcode_atts( ....

在这里为您修改:

function hybrid_entry_comments_link_shortcode( $attr ) {

    $comments_link = '';
    $number = doubleval( get_comments_number() );
    $attr = shortcode_atts( array( 'zero' => __( 'Leave a comment', 'hybrid-core' ), 'one' => __( '%1$s', 'hybrid-core' ), 'more' => __( '%1$s', 'hybrid-core' ), 'css_class' => 'comments-link', 'none' => '', 'before' => '', 'after' => '' ), $attr );

    if ( 0 == $number && !comments_open() && !pings_open() ) {
        if ( $attr['none'] )
            $comments_link = '<span class="' . esc_attr( $attr['css_class'] ) . '">' . sprintf( $attr['none'], number_format_i18n( $number ) ) . '</span>';
    }
    elseif ( 0 == $number )
        $comments_link = '<a class="' . esc_attr( $attr['css_class'] ) . '" href="' . get_permalink() . '#respond" title="' . sprintf( esc_attr__( 'Comment on %1$s', 'hybrid-core' ), the_title_attribute( 'echo=0' ) ) . '">' . sprintf( $attr['zero'], number_format_i18n( $number ) ) . '</a>';
    elseif ( 1 == $number )
        $comments_link = '<a class="' . esc_attr( $attr['css_class'] ) . '" href="' . get_comments_link() . '" title="' . sprintf( esc_attr__( 'Comment on %1$s', 'hybrid-core' ), the_title_attribute( 'echo=0' ) ) . '">' . sprintf( $attr['one'], number_format_i18n( $number ) ) . '</a>';
    elseif ( 1 < $number )
        $comments_link = '<a class="' . esc_attr( $attr['css_class'] ) . '" href="' . get_comments_link() . '" title="' . sprintf( esc_attr__( 'Comment on %1$s', 'hybrid-core' ), the_title_attribute( 'echo=0' ) ) . '">' . sprintf( $attr['more'], number_format_i18n( $number ) ) . '</a>';

    if ( $comments_link )
        $comments_link = $attr['before'] . $comments_link . $attr['after'];

    return $comments_link;
}
于 2012-10-27T22:32:28.073 回答