我悟、我学、我提高

自定义博客作者留言样式

细心的朋友可能已经发现,在评论中我的名字与你们的不大相同。这样做是为了更好的区分读者与博主的留言,当读者在浏览文章的评论时,能够以更清晰的视觉感受来浏览。这个做好的好处是不言而喻的,要实现这个功能非常简单,不需要使用任何插件,只用在 style.css 和 comments.php 中添加几行代码即可,具体的方法如下:

  1. 在comments.php中找到这几行代码:
    <span class=”cmt-author“><?php comment_author_link() ?></span> 其中的 cmt-author 或许是其他的
  2. 打开 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,其中你可以选择使用不同的颜色,或者换成其他的类型
  3. 在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 的形式来显示 评论作者(也就是你)。
  4. 当然除了可以修改名字之外,你也可以修改背景图片或者其他的可以区分你和读者的东西,将以上代码和方法套用在其他地方就可以了。

呵呵,简单吧,那就赶快去修改吧。如果你有其他的更好的方法,不妨告诉我,谢谢啦~ :)


Tagged as:

Comments



Blog Roll