Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress getting current category ID

Tags:

wordpress

I'm trying to get the current ID of the category page I'm viewing.

I had checked the_category_ID

But this echo'd my result when I used

<?php $catID = the_category_ID(); ?>

Is there a way to get it to return the value to the variable so its hidden?

like image 347
ngplayground Avatar asked Mar 05 '13 16:03

ngplayground


People also ask

How do I get the current category slug in WordPress?

Use get_the_category() and then do a print_r() to see what it outputs. It should output an array, and in that case follow the code that pallavi put in the answer.


1 Answers

The current category ID is in the global $cat variable, when you are in a category page.

You can test it with:

<?php echo "Current Category ID is: " . $cat ;?>

when you are in for example this page http://example.com/category/test

like image 177
birgire Avatar answered Oct 15 '22 05:10

birgire