I am new to WP, but I have found two ways through to the current (category page’s) category:
1) There is a “brute force” method: load all categories with get_categories()
, then loop through them and check if each one is the category with is_category()
. This is obviously a heavy task given that the information we are looking *should* be readily available.
2) Another method (but I haven’t tested it for stability) is to bring up the $wp_query variable global $wp_query;
, if you dump it’s contents you will find out a few different places where it gives you category information:
– the name of the category (ex: “thecategory”)
– the ID of the category (ex: 5)
– the tree of the category (ex: “category/subcategory/thecategory”)
This is good because it gives you the tools to avoid confusion between categories with the same name and/or slug.
Hope this helps!