Get category id for category.php page
-
I need to code a way, in category.php, to determine the ID of the category that is being browsed. get_the_category() will not work, because it will return an array of ALL categories assigned to the first post.
e.g., if someone clicks “Fire Department” and that link leads them to “https://ci.champaign.il.us/wordpress/category/city-departments/fire/” (which is a URL for the ‘city-departments > fire’ category page)…
I need to determine in category.php that the FIRE category is what was clicked, EVEN IF the posts happen to be assigned to more than just the fire category.You see, a post might be assigned to the FIRE category and also the HEALTH AND SAFETY category. If I use get_the_category(), it looks like I have no way of knowing that FIRE is the category that is actually being browsed.
One reason I need to determine what category the visitor clicked is that, in category.php, I’m hoping to then find all the first-level child categories of the category chosen.
Any idea how to do this? I have gone through the codex for three days trying to figure it out. Basically, I haven’t found a way to determine the category other than looking at posts on the page, which won’t help.
Sorry if this isn’t making sense… I rewrote the question three times trying to be clearer.
- The topic ‘Get category id for category.php page’ is closed to new replies.