N 个月这前,我介绍过给 WordPress 添加日志签名档的方法,本意是给原创文章加上一个版权信息,结果很快发现在 single.php 中加版权信息这个方面基本起不到作用,最多是给文章加个内链罢了。因为给文章加版权的最终目的,是给转载者一个明确的转载注明方式,但是善意的转载者既使没有看到版权信息也会主动自觉地添加上原文出处,然而有很多恶意采集的垃圾站都是通过 RSS 输出来获取文章内容的,在 single.php 中添加的版权信息并不能在 RSS 中输出,所以在 single.php 中添加版权的方法只能防君子,不能防小人。
今天要介绍的方法是在 WordPress 文章中 feed 输出中添加版权信息,此方法可以弥补上述的不足,不只防君子,最重要的是防止了用垃圾采集站的小人们。方法很简单,只要在 function.php 中加入以下这段代码就行:
function feed_copyright($content) {
if(is_single() or is_feed()) {
$content.= "<blockquote>";
$content.= '<div> » 转载请注明来源:<a title="Life Studio" href="http://wange.im">Life Studio</a> » <a rel="bookmark" title="'.get_the_title().'" href="'.get_permalink().'">《'.get_the_title().'》</a></div>';
$content.= '<div> » 本文链接地址:<a rel="bookmark" title="'.get_the_title().'" href="'.get_permalink().'">'.get_permalink().'</a></div>';
$content.= '<div> » 订阅本站:<a title="Life Studio" href="http://feed.life-studio.cn">http://feed.life-studio.cn</a></div>';
$content.= "</blockquote>";
}
return $content;
}
add_filter ('the_content', 'feed_copyright');
if(is_single() or is_feed()) {
$content.= "<blockquote>";
$content.= '<div> » 转载请注明来源:<a title="Life Studio" href="http://wange.im">Life Studio</a> » <a rel="bookmark" title="'.get_the_title().'" href="'.get_permalink().'">《'.get_the_title().'》</a></div>';
$content.= '<div> » 本文链接地址:<a rel="bookmark" title="'.get_the_title().'" href="'.get_permalink().'">'.get_permalink().'</a></div>';
$content.= '<div> » 订阅本站:<a title="Life Studio" href="http://feed.life-studio.cn">http://feed.life-studio.cn</a></div>';
$content.= "</blockquote>";
}
return $content;
}
add_filter ('the_content', 'feed_copyright');
版权信息的样式可以自己定义,我比较懒,就直接借用了 <blockquote></blockquote> 的样式。再扩展一下,这个功能如此强大,只插版权信息是不是太浪费呢?你也可以插入广告、QQ 在线状态、个性签名……发挥你的想象吧,这些都会在输出的 feed 显示的。
方法转自辐射鱼:http://eachsite.org/auto-insert-content-after-each-post/
-
WordPress 非插件调用最新 Twitter2010年02月11日 -
难道我错怪了 Feedsky?2009年09月22日 -
Feedsky, Come on!2009年08月16日 -
给 Wordpress 添加日志签名档2009年05月29日