Detect category choice for posts with multiple categories

Use:

get_query_var('category-name');

Which will give you:

example.com/category/subcategory/my_post

Which you can then put into any queries you make under category-name.

You can see this in action using the Monkeyman rewrite analyser plugin, by entering one of the URLs for a post and seeing the query variables it generates using those rules

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)