Using this code from the codex:

$category = get_the_category();
echo '<a href="'.get_category_link($category[0]->term_id ).'">'.$category[0]->cat_name.'</a>';

Codex link: http://codex.wordpress.org/Function_Reference/get_the_category

I am able to display the category the post is in as a link (e.g. Business). However, I don't want to display the parent categories. I only want to display the child categories of a certain parent category.

My category structure is like this: Premium (Parent) > Premium Themes (Child) > Ecommerce (Child), Business (Child), Photography (Child), etc.

So I only want to display the children of the Premium Themes category.

Any help much appreciated.

1 Answer 1


your code may look like

$category = get_the_category();
foreach( $category as $cat):
  if($cat[0]->parent == ' your_parent_category_id ( Premium )'){
   echo '<a href="'.get_category_link($cat[0]->term_id ).'">'.$cat[0]->cat_name.'</a>';
  • Thanks, but I couldn't get that to work. But I've found a new snippet. Going to create a new thread so it's less confusing.
    – user34277
    Commented Jun 19, 2013 at 20:54
  • as i visit your new thread, i updated my answer.i think it works for you and in this you do not need to call any additional wordpress function.just insert id of parent category in if condition Commented Jun 20, 2013 at 4:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.