I want to show post count in my site by parent category.
Example -
We have 18 Tutorials, 15 Article, 3 Freebies
Help!
I want to show post count in my site by parent category.
Example -
We have 18 Tutorials, 15 Article, 3 Freebies
Help!
If your categories are already pluralized you can use this:
$categories = get_categories();
echo "We have ";
foreach( $categories as $category )
{
echo $category->count.' '.$category->name.' ';
}
If you would like to pluralize automatically you need two functions:
function ngtj_pluralize($count, $singular, $plural = false)
{
if (!$plural) $plural = $singular . 's';
return ($count == 1 ? $singular : $plural) ;
}
and
function ngtj_list_cats_plural()
{
$categories = get_categories();
echo "We have ";
foreach( $categories as $category )
{
$cat_name = ngtj_pluralize( $category->count, $category->name, $category->name.'s' );
echo $category->count.' '.$cat_name.' ';
}
}You must log in to post.