Wordpress has created a Publishers category. It has many subcategories. How to display the name of the name of the subcategory to which the post belongs, inside the category of publishers.

So far, a way has been found to display only all subcategories of the Pubishers category. And it is necessary specifically the subcategory of the category to which the post belongs.

    1 answer 1

    It is necessary to use such a construction. Where the number 8 is the id of the parent category.

    <?php foreach((get_the_category()) as $childcat) { if (cat_is_ancestor_of(8, $childcat)) { echo '<a href="'.get_category_link($childcat->cat_ID).'" class="cat_link">'; echo $childcat->cat_name . '</a>'; }} ?>