由于本人弄了个微博页来发表些技术论坛的注册信息,但是只在该页显示,于是琢磨着把它显示到最新评论上,正好我使用
的是主题自带的,而小工具内也有,所以就准备修改其为之服务。为了显示指定页就得找到文章的id,可以到数据库内寻找,
最方便的是在后台找到该页,在链接的最后找到post=***,***就是该页ID。然后在wp-includes里编辑
default-widgets.php,先寻找最新评论那块,可搜索 Recent_Comments widget class,这是注释,然后在数据库查找的
指令内添加AND comment_post_ID = ‘***’,***就是刚才找的页面ID,该句可放在AND post_status = ‘publish’的前后
之后修改
- <?php
- if ( $comments ) : foreach ( (array) $comments as $comment) :
- echo '<li class="recentcomments">' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url( get_comment_link($comment->comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';
- endforeach; endif;?>
的内容,就是显示的样式。默认的样式比较不好看,是“作者在某某上发表了评论”类似这种类型,由于我只想显示评论再
加上链接,于是就改成了
- <?php
- if ( $comments ) : foreach ( (array) $comments as $comment) :
- echo "\n<li>" . "<a href=\"" . 'http://www.danfi.cn/miniblog' .
- "#comment-" . $comment->comment_ID . "\">". mb_strimwidth(strip_tags($comment->comment_content),0,40)
- ."</a></li>";
- endforeach; endif;?>
如此就只显示评论了。