<ul>
<li><h2>Archives</h2></li>
<?php
$querystr = "SELECT YEAR(post_date) AS 'year', MONTH(post_date) AS 'month' , count(ID) as posts FROM $wpdb->posts INNER JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) WHERE $wpdb->term_taxonomy.term_id != 12 AND $wpdb->term_taxonomy.parent != 12 AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC";
$years = $wpdb->get_results($querystr);
foreach ( (array) $years as $year ) {
$url = get_month_link( $year->year, $year->month );
$date =mysql2date('F o', $year->year.'-'.$year->month, $translate = true);
echo get_archives_link($url, $date, 'html','<li>',' (' . $year->posts .')</li>');
}
?>
</ul>
To code messed up above.