I'm trying to do the following:
When the user is browsing a category page, I want to get the current category ID. This is what I'm doing:
if(is_category() || is_single()){
foreach(get_the_category() as $category)
{
$current =$category->cat_ID;
$current_name = $category->cat_name;
}
}
echo $current_name . " has id ".$current;
The problem is that when I'm on a category page, get_the_category generates multiple categories, and it's getting the last category output by the function.
I just want the category ID of the category that is currently displayed in the URL.