想在feed中,输出版权信息和随机文章,网上查找了一下,大多数都是在文章页添加,而没有在feed中输出的。照猫画虎,自己实现了一下。将以下代码添加到function.php文件中即可。
function feed_copyright($content) {
if(is_single() or is_feed()) {
$content.= "<blockquote>";
$content.= '<div> » 本文链接地址:<a rel="bookmark" title="'.get_the_title().'" href="'.get_permalink().'">'.get_permalink().'</a></div>';
$content.= "</blockquote>";
}
if(is_feed()){
//我只需要在feed中输出,不需要在正常页面显示
$rand_posts = get_posts('numberposts=5&orderby=rand');
if($rand_posts){
$content.='<p style=" font-weight:bold;">你可能也喜欢:</p>';
$content.= '<ul>';
foreach( $rand_posts as $post ){
$content.='<li><a href="'.get_permalink($post->ID).'" target="_blank">'.$post->post_title.'</a></li>';
}
$content.='</ul>';
}
}
return $content;
}
add_filter ('the_content', 'feed_copyright',0);
近期评论