I’m not a coder so all I can do is try to understand the code and copy/paste code others provide.
The first link shows how to add the actual category name in the body, but not the top-level category (parent/root category).
From the second link I tried several code snippets and again, they do not display the parent/root category in the body class.
From the third link I do not quite understand how to make a code snippet off the information there to display the parent/root category in the body class.
is that for category archives and/or single posts?
For single posts and category archives.
what if a single post has several categories?
You make a valid point there. I totally forgot about the case of multi categories. In this case, I simply want to add a generic class in the body tag. I believe this should be doable with a conditional. Something like
if (categories more than 1)
echo ‘genericClass’;