Hello
you can use the code that you are using in your example
To get Flexicontent category configuration you can
foreach ($categories as $category)
{
$category->config = new JRegistry($category->params);
}
if you want to get item counts then you can use our global (Cached) variable $globalcats
it is cached because it contains also things like item counts that consider multi-category assignments, which can be a little heavy
e.g. 0.2 seconds in large websites,
please do not modify it
if you want to modify assign the array to a new variable
global $globalcats;
$cats = $globalcats;