-
WordPress does this by itself as one of the widgets created. Just add the categories widget to a sidebar or wherever you want and presto, job done!
-
If you need a more customized solution you’ll need to do a bit of coding.
what you want though is wp_list_categories() function.
<ul>
<?php wp_list_categories( array(
'orderby' => 'name',
'show_count' => true, //adds count of posts per category
'include' => array( 10 ) //only includes category with ID 10
) ); ?>
</ul>
see this link for reference: https://developer.wordpress.org/reference/functions/wp_list_categories/