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:
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.
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/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 asked Jun 19, 2013 at 0:19 user34277user34277 53 bronze badges1 Answer
Reset to default 1your 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;
?>