Index: link-template.php
===================================================================
--- link-template.php	(revision 5293)
+++ link-template.php	(working copy)
@@ -286,12 +286,15 @@
 		$join .= ')';
 	}
 
-	$sql_exclude_cats = '';
+	$posts_in_ex_cats_sql = '';
 	if ( !empty($excluded_categories) ) {
-		$blah = explode(' and ', $excluded_categories);
-		foreach ( $blah as $category ) {
+		$excluded_category_list = explode(' and ', $excluded_categories);
+        $sql_cat_ids = '';
+		foreach ( $excluded_category_list as $category ) {
 			$category = intval($category);
-			$sql_cat_ids = " OR pc.category_ID = '$category'";
+            if ($category > 0) {
+                $sql_cat_ids .= " OR pc.category_ID = '$category'";
+            }
 		}
 		$posts_in_ex_cats = $wpdb->get_col("SELECT p.ID FROM $wpdb->posts p LEFT JOIN $wpdb->post2cat pc ON pc.post_id=p.ID WHERE 1 = 0 $sql_cat_ids GROUP BY p.ID");
 		$posts_in_ex_cats_sql = 'AND ID NOT IN (' . implode($posts_in_ex_cats, ',') . ')';
@@ -323,12 +326,15 @@
 		$join .= ')';
 	}
 
-	$sql_exclude_cats = '';
+	$posts_in_ex_cats_sql = '';
 	if ( !empty($excluded_categories) ) {
-		$blah = explode(' and ', $excluded_categories);
-		foreach ( $blah as $category ) {
+		$excluded_category_list = explode(' and ', $excluded_categories);
+        $sql_cat_ids = '';
+		foreach ( $excluded_category_list as $category ) {
 			$category = intval($category);
-			$sql_cat_ids = " OR pc.category_ID = '$category'";
+            if ($category > 0) {
+                $sql_cat_ids .= " OR pc.category_ID = '$category'";
+            }
 		}
 		$posts_in_ex_cats = $wpdb->get_col("SELECT p.ID from $wpdb->posts p LEFT JOIN $wpdb->post2cat pc ON pc.post_id = p.ID WHERE 1 = 0 $sql_cat_ids GROUP BY p.ID");
 		$posts_in_ex_cats_sql = 'AND ID NOT IN (' . implode($posts_in_ex_cats, ',') . ')';
