Thanks to wordpress.org, the snippet below will display a list child categories link only for each respective post if there's a child category for them.
<?php
foreach((get_the_category()) as $category) {
if ($category->category_parent != 0) {
echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr(strip_tags($category->name)) . '" ' . '>' . $category->name.'</a> ';
}
}
?>
Now I'm looking for a different snippet that'll display a list of parent categories only. Anyway how to get the parent category only?
if
logic - instead of checking it has a parent, check that it doesn't i.e.if ( ! $category->category_parent )