Category icon or image for child categories of a specific parent by ID used in the loop
Description
This code will create a category icon or image for child categories of a specific parent by ID used in the loop. In order to choose create parent and child categories and create images that have a file name that matches the category. In this example change 3 to the id of the parent that […]
This code will create a category icon or image for child categories of a specific parent by ID used in the loop. In order to choose create parent and child categories and create images that have a file name that matches the category. In this example change 3 to the id of the parent that you want to show children for. images must be a .png
PHP Source Code
<!--Get icon start-->
<?php
foreach((get_the_category()) as $childcat) {
if (cat_is_ancestor_of(3, $childcat)) {
echo '<img src="http://if-sandbox.com/wp-content/themes/seek/img/flags/' . $childcat->cat_ID . '.png" alt="' . $childcat->cat_name . '" />';
}}
?>
<!--Get icon End-->