On my author page I currently have a list of categories the author has posted in generated by the following code:
<?php
$categories = $wpdb->get_results("
SELECT DISTINCT(terms.term_id) as ID, terms.name, terms.slug
FROM $wpdb->posts as posts
LEFT JOIN $wpdb->term_relationships as relationships ON posts.ID = relationships.object_ID
LEFT JOIN $wpdb->term_taxonomy as tax ON relationships.term_taxonomy_id = tax.term_taxonomy_id
LEFT JOIN $wpdb->terms as terms ON tax.term_id = terms.term_id
WHERE 1=1 AND (
posts.post_status = 'publish' AND
posts.post_author = $curauth->ID AND
tax.taxonomy = 'category' )
ORDER BY terms.name ASC
");
$x = 0;
?>
<ul class="category-list">
<?php foreach($categories as $category) : ?>
<?php if( $x%2 ){ ?>
<li class="odd">
<?php } else { ?>
<li>
<?php } ?>
<a href="<?php echo get_category_link( $category->ID ); ?>" title="<?php echo $category->name ?>"><?php echo $category->name ?></a>
</li>
<?php $x++; endforeach; ?>
</ul>
What I'm after doing is to add the number of posts within each category in the foreach loop, next to the category in parentheses.
Any idea how would I go about doing so?
Thanks!