Home » Wordpress 技巧

把WordPress博客中的Trackbacks和评论分离

这篇文章翻译自problogdesign.com 的Separating Trackbacks from Comments

在WordPress博客中,trackbacks 就是当有人在他的博客做对你的文章做回链时就会在评论中显示出来链接。一般的主题都会显示出文章的回链。

如果你的博客中也显示trackbacks 的话,那么最好不要把它和文章的评论混合在一起。评论可以说是读者与读者以及博客的作者之间的对话,而如果随机产生的trackbacks掺杂在其中的话,就会给人一种打断这种对话的感觉。

这里介绍的方法就是帮你将文章中的trackbacks从评论中分离开来,并让它在评论的下面列出来。照了下面的方法做之后,你如果还想对trackbacks 如何显示进行修改的话,那将会是一件很容易的事。

这里要感谢 Gary,让我们可以做到 Trackbacks 这一块只有在有trackback时才会显示。

如何把 Trackbacks分离开来?

打开wordpress 中的 comments.php 文件,然后搜索下面的代码:

<?php foreach ($comments as $comment) : ?>

在这些代码的下面加入下面的代码:

<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type == 'comment') { ?>

然后在搜索这些代码:

<?php endforeach; /* end for each comment */ ?>

在前面加上下面的代码:

<?php } else { $trackback = true; } /* End of is_comment statement */ ?>

上面的代码是使文章的评论正常显示,不过在这里不会显示任何 trackbacks 或者 pingbacks. 接下来,我们就要加第二个 comments loop来显示 trackbacks。

搜索下面的代码:

<?php else : // this is displayed if there are no comments so far ?>

在它的前面,加入下面的代码 ( “Trackbacks” 是这一块的标题,如果你不喜欢,可以把它删除掉)


<?php if ($trackback == true) { ?>
<h3>Trackbacks</h3>
<ol>
<?php foreach ($comments as $comment) : ?>
<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type != 'comment') { ?>
<li><?php comment_author_link() ?></li>
<?php } ?>
<?php endforeach; ?>
</ol>
<?php } ?>

当然,这种方法只有在你的博客是使用Trackbacks的情况下才有用。那么你的博客中是否使用Trackbacks呢?

Popularity: 1% [?]

Share/Bookmark this!

Leave a reply

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally recognized avatar, please register at Gravatar.

Side Notes

This entry was posted by 莫 涯 on May 30, 2009 at 9:46 pm and filed under Wordpress 技巧 category.

You can add your comments or trackback from your own site. To keep you updated to the latest discussion, you can subscribe to these comments via RSS.

This is a Gravatar-enabled weblog. To get your own globally recognized avatar, please register at Gravatar.

最新文章

最新评论

Tag Cloud

301 Redirect 301重定向 2010 about All in one seo pack AutosCraze blog CSS Darren feed FreshMag Global Translator Google GreenFun HTML Insider name.com Problogger robots.txt文件 RSS Feed seo Wordpress Wordpress 主题 Wordpress主题 代码 优惠码 关于 博客 博客建设 域名 工具 建设 技巧 提交 插件 文章 杂志型主题 标签 注册 绿色 网赚 评论 选择 链接 页面