Getting the Category ID
-
Hi guys,
My name is Alek and I have a pretty good amount of experience with WordPress. However, while trying to design a theme for one of my friends, I was intercepted by something I personally think simple, yet hard to figure out. I’m basically trying to Display the sub-categories of a category in a drop down select list, which is fairly easy, but not the way I want to do it. My friend has around 50 categories and over 1000 sub categories(What the ??? Go figure..) Anyways, he wants that drop down list to display only the subcategories of the category you’re situated at the time of the request.For example:
You’re at: http://www.testdomain.com/category/bananas/
So you went that drop-down list to display all of the subcategories in the “Bananas” category. Here’s what I have so far.
<?php wp_dropdown_categories('show_option_none=Select One&orderby=name&child_of=<?php get_the_category(); ?>&hide_empty=0&hierarchical=0'); ?>, which apparently isn’t working. I can always go ahead and manually create a category-id.php template for each different category, or wait untill he updates to 3.0 and create category-slug.php , but with how crazy he is in mind, he would probably come up with at least another 50 in the next year, so that will only mean more and more work. Does anyone have an idea? I will keep on looking at the codex, but i can’t find the right snippet of code.
I could use something like
<?php $current_category = single_cat_title("", false); ?>And then use $current_category as a variable in php, however, there is no such hook for category id, and child_of uses category id.
Thanks a lot in advance.
Help is much appreciated.
The topic ‘Getting the Category ID’ is closed to new replies.