views:

2050

answers:

2

I tried getting help on the wordpress forums but no luck. Anyways, heres my question...

Lets say i am creating 10 parent categories and 2 sub categories to each parent. My wordpress post belongs to one sub category of a particular parent category

How do i get the parent category name ONLY? i don't want subcategories names? what wordpress code would do that?

And one more question...

Is it possible to query post by the parent of a sub category by using

but instead of entering "cat=1" or the name of the particular category, can I do something like

so this way it would automatically insert and query post for the parent of any particular sub category that's clicked on?

A: 

Lots of answers and examples in the Wordpress docs:

get category parents

get the category

(And it looks like some code snips or other text didn't come through in your original question)

songdogtech
A: 

To get the parent category name, use the get_cat_name() function, with the parent as the parameter -- like so:

$cat = get_the_category();
$parentCatName = get_cat_name($cat[0]->parent);
Blago