How to print only Parent Category name in single.php? (wordpress)
My structure:
Category A
-SubCategory X
- The post (article) is posted only to Subcategory X.
- I want to print only the name of "Category A".(without html tag).
How to print only Parent Category name in single.php? (wordpress)
My structure:
Category A
-SubCategory X
I think you try this code: for me this is working............
<?php $parentscategory ="";
foreach((get_the_category()) as $category) {
if ($category->category_parent == 0) {
$parentscategory .= ' <a href="' . get_category_link($category->cat_ID) . '" title="' . $category->name . '">' . $category->name . '</a>, ';
}
}
echo substr($parentscategory,0,-2); ?>