Code: Select all
<?php
foreach((get_the_category()) as $childcat)
{
if (cat_is_ancestor_of(10, $childcat))
{
echo '<a href="'.get_category_link($childcat->cat_ID).'">'; echo $childcat->cat_name . '</a>' . ', ';
}
}
?>
I got the closest using substr but it deleted all of the comma's, not just the last one. Here is the code I used for that:
Code: Select all
<?php
foreach((get_the_category()) as $childcat)
{
if (cat_is_ancestor_of(10, $childcat))
{
$str = '<a href="'.get_category_link($childcat->cat_ID).'">' . $childcat->cat_name . '</a>' . ', ';
substr($str, 0, -2); echo $str;
}
} ?>