# get current category ID php

I'm trying to get category ID of the current archive displayed.

I tried:

// category (can be a parent category)
$current_cat_ID = get_query_var('cat'); // print_r ($current_cat_ID);


It doesn't print anything...

-
where in the template is the code located? are there any custom queries before the code? –  Michael Jul 24 '12 at 14:21
will cat always be set regardless of permalink structure, or maybe just category_name in some cases? I can't recall at the moment... –  Milo Jul 24 '12 at 14:29

you can use get_queried_object()

$category = get_queried_object(); echo$category->term_id;

-