$category = get_the_category(); echo $category->cat_name;
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.