Listing Top Categories in Wordpress
For my footer, I wanted to list the top ten categories (as calculated by the number of posts in each category). Bizarrely enough, there isn't an easy built-in way to do this with Wordpress. What's more surprising is that I couldn't find a plugin that provided this functionality, either. Maybe I'm the only person with this requirement. At any rate, this is how I solved the issue:
<?php$top_cats = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY category_count DESC LIMIT 10");foreach($top_cats as $cat){$cat_link = '<a href="index.php"' . $cat->category_nicename . '">';$cat_li = "<li>$cat_link $cat->cat_name</a></li> ";echo($cat_li);}?>