In wordpress, sometimes you may have many subcategories for a different parent categories. By default wordpress lists all sub-categories.
if i have category structure like
Drupal
– 2 Column
– 3 Column
– Left sidebar
– Right sidebarWordPress
– Fixed Width
– Widget Ready
– News/Magazine
– Photogallery
and if i do a wordpress post (with title say CSS Gallery) inside WordPress -> Photogallery i want the title to display
Blog Title > Parent Category Name > Blogpost Title
likeTop Best Themes > WordPress > CSS Gallery
Here is the wordpress code to display parent category name. Its a very simple code but did the job for me. You can insert inside header.php if you want to change titles in wordpress. This is how it works. First it gets the category name of wordpress post, and from it gets the Category ID of its parent then it gets the parent name with get_cat_name() function. If the parent is empty (which means the wordpress post is already listed in the parent category) then print the current category name.
<?php
$category = get_the_category();
$parent = get_cat_name($category[0]->category_parent);
if (!empty($parent)) {
echo '» ' . $parent;
} else {
echo '» ' . $category[0]->cat_name;
}
?>
Note that this code has a limitation and it works best with only one level deep.!