During the last year(s), the main interest in the WordPress comunity was undoubtly the emulation of magazine websites; the previously blogging platform became a full CMS, and theme authors have become preocupied in turning the classic blog layout into a magazine-like design. A new era of theme development was born.
A magazine-style theme is made possible by the use of WordPress categories. By the means of a PHP query, the template asks the database a number of posts filled under a certain cat and displays them on the homepage. The template asks the posts either calling the category name, or pointing to the category-id.
The problem
The problem is that the last versions of WordPress (2.3 to 2.7) hide the category-ids from the blog users. In the prior versions, the ids were listed in the Manage > Categories section, right next to the name. One could hardly find an easier task than retrieving them.
What are category-ids
Category-ids are numbers. Imagine the database of your blog is a library. The posts are the books, their unique ids are the ISBNs, the tags are the book-shelves and the categories are the storing-rooms. In this analogy, your WordpPress installation is the librarian, while the template (specifically the home.php file) is a student asking a few books. As simple as that.
Like any library, the WordPress database will reference posts using a specific pattern; to avoid any confusion, the books and the rooms they’re stored in will recieve unique ids, expressed in numbers.
Retrieving the ids
There are al least three ways of figuring out what is the id of a specific category:
1. The first one is running a MySQL query, but I wouldn’t recomend it, in case you’re not acquainted to the MySQL secrets. Anyway, the other two ways are much easier and more secure.
2. The second one consists in simply reading the source of a page that lists your blog’s categories. Just take a look at this picture:
As you can see, the HTML outputed by the wp_list_categories tag preserve the cat id under the name “cat-item-x”.
3. If you hate reading scripts, there is still hope. In the admin area of your blog, go to Posts > Categories section. You’ll see a nice list containing the names of your cats, their respectives slugs and the number of posts they contain. Now mouseover the name of a category and look at the status bar (I assume you’re using Mozilla). You should see something like this:
That’s it. The number at the end of the URL displayed in the status bar is the id of the catecory you mouseovered.
Hocus-pocus, and the configuration of a magazine-style theme was never easier.
Published on the 17th of February, 2009, in WordPress · Print


Thanks a ton for sharing this !! I m searching in hell till now.But got d answer here.
I have permalinks set up.
Before permalinks setup I have query string like this,
http://localhost/wordpress/products-page?category=2&product_id=11
And by changing it to permalinks to numeric,
It shows ;
http://localhost/wordpress/products-page/po-campo1/product-3
There is
po-campo1 is category
product-3 is product in po-campo1 category.
So, how can I get category_id and product_id at the top of the page?
If you know that please share it with me, I really need it.
Thanks.