Wordpress最新评论widgets调整

默认情况下,Wordpress最新评论widgets的形式为:
newest_comment_original
也就是 >>comment_author 在 comment_post_ID 上的评论
我现在需要把评论者的站点链接和评论内容链接去掉,然后改成这样:
>>comment_author 说道:comment_content >>

(本文以WP2.7中本版为例)
先在网路上抓个Poedit下来,安装好,当然有Chinese Simplifed就再好不过了,编辑Wordpress目录下的\wp-content\languages\zh_CN.po

搜索“上的评论” 定位到第一个搜索到的“上的评论” ,可以发现是这样的:
原文:%1$s on %2$s
译文:%1$s 在 %2$s 上的评论
现在把译文改成这样:%1$s 说道: %2$s ,保存zh_CN.po

接下来用任意编辑器打开\wp-includes\comment-template.php,定位到132到150行:

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/**
 * Retrieve the html link to the url of the author of the current comment.
 *
 * @since 1.5.0
 * @uses apply_filters() Calls 'get_comment_author_link' hook on the complete link HTML or author
 *
 * @return string Comment Author name or HTML link for author's URL
 */

function get_comment_author_link() {
    /** @todo Only call these functions when they are needed. Include in if... else blocks */
    $url    = get_comment_author_url();
    $author = get_comment_author();

    if ( empty( $url ) || 'http://' == $url )
        $return = $author;
    else
        $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>";
    return apply_filters('get_comment_author_link', $return);
}

以上代码是get_comment_author_link()的定义,当$url变量有值的时候,返回一个带链接的author,我不需要链接,所以改为:

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/**
 * Retrieve the html link to the url of the author of the current comment.
 *
 * @since 1.5.0
 * @uses apply_filters() Calls 'get_comment_author_link' hook on the complete link HTML or author
 *
 * @return string Comment Author name or HTML link for author's URL
 */

function get_comment_author_link() {
    /** @todo Only call these functions when they are needed. Include in if... else blocks */
    $url    = get_comment_author_url();
    $author = get_comment_author();

    if ( empty( $url ) || 'http://' == $url )
        $return = $author;
    else
        $return = "$author";
    return apply_filters('get_comment_author_link', $return);
}

接下来打开wp-includes\widgets.php 定位到1399到1402行:

1399
1400
1401
1402
1403
<ul id="recentcomments"><?php
if ( $comments ) : foreach ( (array) $comments as $comment) :
echo  '<li class="recentcomments">' . sprintf(__('%1$s on %2$s'), get_comment_author_link(), '<a href="'. get_comment_link($comment->comment_ID) . '">' . <span style="text-decoration: underline;">get_the_title($comment->comment_post_ID)</span> . '</a>') . '</li>';
endforeach; endif;?>
</ul>

下划线部分改为:$comment->comment_content  ,保存。

好了,搞定,看下效果:
wordpress_newest_comment_modified

需要改代码,有点麻烦,不过生命就是在于折腾!

也许你对以下文章感兴趣

Tags: ,  

4 Comments

  1. 直接用中文的多好,省着用ProEdit

    Reply

    tunpishuang Reply:

    我就是用的中文版,但是也要用到poedit这个工具。

    Reply

  2. 你好,我按照你说的做,怎么没有变化呢?还是原来那样!

    Reply

    tunpishuang Reply:

    按照这个方法一步步的来应该没问题。

    Reply

留下评论

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image