How to displaying a posts current category and parent category?

We found that wordpress default templete or classic template does not show a post category’s parent category if the post category has its parent category. As we know a website inner link is also very important for human being reading or for seo purpose. The fucntion of “the_category” only a post category, not show the category’s parent category.

We have to write some custom code to achieve listing the current post to the current category and it’s parent. Here are the code:

category_parent;
if ( $parent_category != 0 ) {
echo ‘Post under: ‘ . get_cat_name($parent_category) . ‘-‘;
}
echo ‘‘ . $current_category->cat_name . ‘‘;
?>

Hope it is a little useful for you.