Just call get_categories()
. You’ll get back an array of term objects:
array(
[0] => WP_Term Object
(
[term_id] =>
[name] =>
[slug] =>
[term_group] =>
[term_taxonomy_id] =>
[taxonomy] =>
Echo show_count of categories separately without using wp_list_categories =>
[parent] =>
[count] =>
[filter] =>
)
)
You can process this with wp_list_pluck
to turn it into an associative array, so for example:
$cat_counts = wp_list_pluck( get_categories(), 'count', 'name' );
This will return an array like:
array(
'Geography' => 5,
'Maths' => 7,
'English' => 3,
)
For other taxonomies use get_terms()
instead. get_categories()
is really not much more than a wrapper for get_terms()
.
To show these like the picture you’ve added to your question, just loop over the array.
echo '<dl>';
// use whichever HTML structure you feel is appropriate
foreach ( $cat_counts as $name => $count ) {
echo '<dt>' . $name . '</dt>';
echo '<dd>' . sprintf( "%02d", $count ) . '</dd>';
// use sprintf to specify 2 decimal characters with leading zero if necessary
}
echo '</dl>';