WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Using this code from the codex:

       <?php
$category = get_the_category();
if($category[0]){
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.

share|improve this question

your code may look like

<?php
$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>';
  break;
  }
endforeach;
?>
share|improve this answer
    
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 Jun 19 '13 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 – Ravinder Kumar Jun 20 '13 at 4:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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