评论链接在Origin wordpress主题的短代码中

时间:2012-10-27 22:26:21

标签: php wordpress comments

我正在使用word主题的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;
}

1 个答案:

答案 0 :(得分: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;
}