I'm using:
$category = get_the_category();
echo $category[0]->cat_name;
to display the current category as a header in an archive template (example of local url is http://imac.local:5757/category/accommodation/, http://imac.local:5757/category/service/ etc)
For the first 3 categories, this works fine, but after that it's showing a child category instead. I've tried changing the slug of the posts and the category, updating the permalinks, unpublishing posts in the child category which is showing (it then shows another child category instead) - but none of this solves the problem.
I suppose it's a clash of slugs & permalinks somewhere, but changing these doesn't seem to fix it. Is there more specific wordpress php which can be written to avoid this clashing?
I did find this post: Archived Posts in Wrong Category but it doesn't seem to be the same problem.
Thanks