自定义博客作者留言样式
细心的朋友可能已经发现,在评论中我的名字与你们的不大相同。这样做是为了更好的区分读者与博主的留言,当读者在浏览文章的评论时,能够以更清晰的视觉感受来浏览。这个做好的好处是不言而喻的,要实现这个功能非常简单,不需要使用任何插件,只用在 style.css 和 comments.php 中添加几行代码即可,具体的方法如下:
- 在comments.php中找到这几行代码:
<span class=”cmt-author“><?php comment_author_link() ?></span> 其中的 cmt-author 或许是其他的 - 打开 style.css ,在文件中搜索 cmt-author ,然后在
.cmt-author {
display: block;
background: transparent url(images/indicator_date.gif) no-repeat right center;
padding: 0 15px;
font-weight: bold;
}
.cmt-author a:link,
.cmt-author a:visited,
.cmt-author a:hover,
.cmt-author a:active {
color: #fff;
}
这几行代码下加上这几行代码
.cmt-author2 {
display: block;
background: transparent url(images/indicator_date.gif) no-repeat right center;
padding: 0 15px;
font-weight: bold;
}
.cmt-author2 a:link,
.cmt-author2 a:visited,
.cmt-author2 a:hover,
.cmt-author2 a:active {
color: blue;
}
cmt-author2 这几行代码是为你自己的名字设计的CSS,其中你可以选择使用不同的颜色,或者换成其他的类型 - 在comments.php中,将
<span class=”cmt-author”><?php comment_author_link() ?></span>
替换为
<?php $class=’cmt-author’;
if(apply_filters(‘comment_author_email’,
$comment->comment_author_email) == ‘你的邮箱地址‘) { $class =
‘cmt-author2′; } ?>
<span class=”<?=$class?>”><?php comment_author_link() ?></span>
这句代码的意思是,当你的读者发表评论时,以 cmt-author 的形式来显示 评论作者 ,当你发表评论时,以cmt-author2 的形式来显示 评论作者(也就是你)。 - 当然除了可以修改名字之外,你也可以修改背景图片或者其他的可以区分你和读者的东西,将以上代码和方法套用在其他地方就可以了。
呵呵,简单吧,那就赶快去修改吧。如果你有其他的更好的方法,不妨告诉我,谢谢啦~
不错的方法 我也试试看
嘿嘿,这样做会有很多好处的,赶快去试试吧~
哈哈搞定 效果不错 好文
非常高兴你这么说,你可以将这个方法告诉更多的人
现在用的模板已经区分了,就是评论与回复的底色不一样。 yskin的修改挺漂亮,建议去看GuestBook页面,http://yskin.net/guestbook/
我本来也是实现了和他差不多的功能,后来修改成现在的样子了,呵呵,个人的喜好不同。
hi all. nice site. by.