get_results("SELECT * FROM $wpdb->categories WHERE category_count > 0 ORDER BY cat_name DESC"); // query database for categories with at least one post;
foreach($categories as $category) : // start loop to display category list
?>
cat_name; ?>
cat_ID;
endif;
if( (is_category() || is_single()) && ($category->cat_ID === $cat) ) : // current category query is same as category presently in the loop
?>
have_posts()) : $catq->the_post(); // start posts in category loop
?>