Misterpayne112
Member
Posted 2 weeks ago #
i want to display the number of posts in each category, next to the link for that category in my sidebar. i am using...
<?php list_cats(FALSE, ' ', 'name'); ?>
that displays all categories in a nice neat list, but i want the number of posts in each category right next to the link. how do i do that?
Maybe try something like..
<?php
$args = array('pad_counts' => true, 'get' => 'all');
$cats = get_terms('category', $args);
?>
<?php foreach( $cats as $category ) : ?>
<a href="<?php echo get_category_link( $category->term_id ); ?>"><?php echo $category->name; ?></a>
<?php echo $category->count; ?> posts<br />
<?php unset( $category ); ?>
<?php endforeach; unset( $cats ); ?>
Function information:
http://codex.wordpress.org/Function_Reference/get_terms
Remember list_cats is deprecated in favor of the template tag, wp_list_categories(), which has a show_count=1 argument.
... get_terms is faster though ... :p ... ;)
Misterpayne112
Member
Posted 1 week ago #
thanks t31os_ it worked like a charm! Thanks everyone else too!