Index: feed-atom.php
===================================================================
--- feed-atom.php	(revision 10904)
+++ feed-atom.php	(working copy)
@@ -5,8 +5,23 @@
  * @package WordPress
  */
 
+function echo_feed_subtitle() {
+	$feed_subtitle=get_bloginfo_rss("description");
+	if(!empty($feed_subtitle)) {
+		echo '<subtitle type="text">'.$feed_subtitle.'</subtitle>'."\n";
+	}
+}
+function get_query_id() {
+	global $wp_query;
+	return $wp_query->get_queried_object_id();
+}
+function echo_atom_feed_links($selfLink,$alternateLink,$repliesLink) {
+	echo '<link rel="self" type="application/atom+xml" href="'.$selfLink.'" />'."\n".'<link rel="alternate" type="text/html" href="'.$alternateLink.'" />'."\n".'<link rel="replies" type="application/atom+xml" href="'.$repliesLink.'" />'."\n";
+}
+
 header('Content-Type: ' . feed_content_type('atom') . '; charset=' . get_option('blog_charset'), true);
 $more = 1;
+$feed_type="atom";
 
 ?>
 <?php echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>
@@ -17,17 +32,35 @@
   xml:base="<?php bloginfo_rss('home') ?>/wp-atom.php"
   <?php do_action('atom_ns'); ?>
  >
+	<id><?php bloginfo('atom_url'); ?></id>
 	<title type="text"><?php bloginfo_rss('name'); wp_title_rss(); ?></title>
-	<subtitle type="text"><?php bloginfo_rss("description") ?></subtitle>
-
-	<updated><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_lastpostmodified('GMT')); ?></updated>
+<?php
+if(is_category()) {
+	$cat_id=get_query_id();
+	echo_atom_feed_links(get_category_feed_link($cat_id),get_category_link($cat_id),get_category_comments_feed_link($cat_id,$feed_type));
+}
+elseif(is_tag()) {
+	$tag_id=get_query_id();
+	echo_atom_feed_links(get_tag_feed_link($tag_id),get_tag_link($tag_id),get_tag_comments_feed_link($tag_id,$feed_type));
+}
+elseif(is_author()) {
+	$author_id=get_query_id();
+	echo_atom_feed_links(get_author_feed_link($author_id),get_author_posts_url($author_id),get_author_comments_feed_link($author_id,$feed_type));
+}
+elseif(is_date()) {
+	/* To be done */
+}
+elseif(is_search()) {
+	$search_query=get_search_query();
+	echo_atom_feed_links(get_search_feed_link($search_query,$feed_type),get_search_link($search_query),get_search_comments_feed_link($search_query,$feed_type));
+}
+else {
+	echo_feed_subtitle();
+	echo_atom_feed_links(get_bloginfo('atom_url'),get_bloginfo_rss('url').'/',get_bloginfo_rss('comments_atom_url'));
+}?>
 	<?php the_generator( 'atom' ); ?>
-
-	<link rel="alternate" type="text/html" href="<?php bloginfo_rss('home') ?>" />
-	<id><?php bloginfo('atom_url'); ?></id>
-	<link rel="self" type="application/atom+xml" href="<?php self_link(); ?>" />
-
 	<?php do_action('atom_head'); ?>
+	<updated><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_lastpostmodified('GMT')); ?></updated>
 	<?php while (have_posts()) : the_post(); ?>
 	<entry>
 		<author>
@@ -41,7 +74,7 @@
 		<id><?php the_guid(); ?></id>
 		<updated><?php echo get_post_modified_time('Y-m-d\TH:i:s\Z', true); ?></updated>
 		<published><?php echo get_post_time('Y-m-d\TH:i:s\Z', true); ?></published>
-		<?php the_category_rss('atom') ?>
+		<?php the_category_rss($feed_type) ?>
 		<summary type="<?php html_type_rss(); ?>"><![CDATA[<?php the_excerpt_rss(); ?>]]></summary>
 <?php if ( !get_option('rss_use_excerpt') ) : ?>
 		<content type="<?php html_type_rss(); ?>" xml:base="<?php the_permalink_rss() ?>"><![CDATA[<?php the_content('', 0, '') ?>]]></content>
@@ -49,7 +82,7 @@
 <?php atom_enclosure(); ?>
 <?php do_action('atom_entry'); ?>
 		<link rel="replies" type="text/html" href="<?php the_permalink_rss() ?>#comments" thr:count="<?php echo get_comments_number()?>"/>
-		<link rel="replies" type="application/atom+xml" href="<?php echo get_post_comments_feed_link(0,'atom') ?>" thr:count="<?php echo get_comments_number()?>"/>
+		<link rel="replies" type="application/atom+xml" href="<?php echo get_post_comments_feed_link(0,$feed_type) ?>" thr:count="<?php echo get_comments_number()?>"/>
 		<thr:total><?php echo get_comments_number()?></thr:total>
 	</entry>
 	<?php endwhile ; ?>
Index: link-template.php
===================================================================
--- link-template.php	(revision 10904)
+++ link-template.php	(working copy)
@@ -5,7 +5,99 @@
  * @package WordPress
  * @subpackage Template
  */
+ 
+ function get_category_comments_feed_link($cat_id, $feed = '') {
+	$cat_id = (int) $cat_id;
 
+	$category = get_category($cat_id);
+
+	if ( empty($category) || is_wp_error($category) )
+		return false;
+
+	if ( empty($feed) )
+		$feed = get_default_feed();
+
+	$permalink_structure = get_option('permalink_structure');
+
+	if ( '' == $permalink_structure ) {
+		$link = get_option('home') . "?feed=comments-$feed&amp;cat=" . $cat_id;
+	} else {
+		$link = get_category_link($cat_id);
+		if( $feed == get_default_feed() )
+			$feed_link = 'comments/feed';
+		else
+			$feed_link = "comments/feed/$feed";
+
+		$link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
+	}
+
+	$link = apply_filters('category_comments_feed_link', $link, $feed);
+
+	return $link;
+}
+function get_tag_comments_feed_link($tag_id, $feed = '') {
+	$tag_id = (int) $tag_id;
+
+	$tag = get_tag($tag_id);
+
+	if ( empty($tag) || is_wp_error($tag) )
+		return false;
+
+	$permalink_structure = get_option('permalink_structure');
+
+	if ( empty($feed) )
+		$feed = get_default_feed();
+
+	if ( '' == $permalink_structure ) {
+		$link = get_option('home') . "?feed=comments-$feed&amp;tag=" . $tag->slug;
+	} else {
+		$link = get_tag_link($tag->term_id);
+		if ( $feed == get_default_feed() )
+			$feed_link = 'comments/feed';
+		else
+			$feed_link = "comments/feed/$feed";
+		$link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
+	}
+
+	$link = apply_filters('tag_comments_feed_link', $link, $feed);
+
+	return $link;
+}
+function get_author_comments_feed_link( $author_id, $feed = '' ) {
+	$author_id = (int) $author_id;
+	$permalink_structure = get_option('permalink_structure');
+
+	if ( empty($feed) )
+		$feed = get_default_feed();
+
+	if ( '' == $permalink_structure ) {
+		$link = get_option('home') . "?feed=comments-$feed&amp;author=" . $author_id;
+	} else {
+		$link = get_author_posts_url($author_id);
+		if ( $feed == get_default_feed() )
+			$feed_link = 'comments/feed';
+		else
+			$feed_link = "comments/feed/$feed";
+
+		$link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
+	}
+
+	$link = apply_filters('author_comments_feed_link', $link, $feed);
+
+	return $link;
+}
+function get_search_link($search_query) {
+	if (empty($search_query)) {
+		$search=attribute_escape(get_search_query());
+	}
+	else {
+		$search=attribute_escape(stripslashes($search_query));
+	}
+	$link=get_option('home')."?s=$search";
+	$link=apply_filters('search_link',$link);
+	return $link;
+}
+
 /**
  * Display the permalink for the current post.
  *
