Index: template.php
===================================================================
--- template.php	(revision 40727)
+++ template.php	(working copy)
@@ -81,6 +81,15 @@
 /**
  * Retrieve path of 404 template in current or parent template.
  *
+ * Will attempt to retrieve templates specific to the query vars that are
+ * present in the URL returning a 404 error. For example, if the tag query
+ * var is set, 404-tag.php and 404-archive.php will be returned in addition
+ * to the default 404.php.
+ *
+ * Works by looping through the '$checks' array and checking to see if each 
+ * query var is set. If one is, the template slugs for that query var will be 
+ * looped through to build the template filenames.
+ *
  * The template hierarchy is filterable via the {@see '404_template_hierarchy'} hook.
  * The template path is filterable via the {@see '404_template'} hook.
  *
@@ -91,7 +100,39 @@
  * @return string Full path to 404 template file.
  */
 function get_404_template() {
-	return get_query_template('404');
+	
+	$checks = array(
+		'taxonomy'      => array( 'taxonomy-%s', 'taxonomy', 'archive' ),
+		'attachment'    => array( 'attachment', 'single', 'singular' ),
+		'attachment_id' => array( 'attachment', 'single', 'singular' ),
+		'p'             => array( 'single', 'singular' ),
+		'name'          => array( 'single', 'singular' ),
+		'page_id'       => array( 'page', 'singular' ),
+		'post_type'     => array( 'single-%s', 'single', 'singular' ),
+		'cat'           => array( 'category', 'archive' ),
+		'category_name' => array( 'category', 'archive' ),
+		'tag'           => array( 'tag', 'archive' ),
+		'author'        => array( 'author', 'archive' ),
+		'm'             => array( 'date', 'archive' ),
+		'year'          => array( 'date', 'archive' ),
+		'monthnum'      => array( 'date', 'archive' ),
+		'day'           => array( 'date', 'archive' ),
+	);
+	
+	$templates = array();
+	
+	foreach ( $checks as $query_var => $template_slugs ) {
+		if ( $query_var = get_query_var( $query_var ) ) {
+			foreach ( $template_slugs as $template_slug ) {
+				$templates[] = '404-' . sprintf( $template_slug, $query_var ) . '.php';
+			}
+			break;
+		}
+	}
+	
+	$templates[] = '404.php';
+	
+	return get_query_template( '404', $templates );
 }
 
 /**
