Hello!
I'm using the code below to list out a portfolio item's categories (with no link). Works great, but it outputs the categories one right after another with no separator. I'd like to add a comma to separate them, if possible.
<?php
$categories = get_the_category();
foreach($categories as $category) {
if ($category->category_parent == 0) continue;
echo str_replace('-', '', $category->name).' ';
}
?>
Thanks!
Mike
Julian Lannigan answers:
Try this:
<?php
$categories = get_the_category();
$temp = array();
foreach($categories as $category) {
if ($category->category_parent == 0) continue;
$temp[] = str_replace('-', '', $category->name);
}
echo implode(", ", $temp);
?>
Mike McAlister comments:
Perfect, Julian. Thanks!
Mike