ID); // comma-separate posts $separator = ', '; // create output variable $output = ''; // if there are categories for the post if($categories){ echo '

'; echo '' . __("Published in", "apex") . ' '; foreach($categories as $category) { // if it's the last and not the first (only) category, pre-prend with "and" if( $category === end($categories) && $category !== reset($categories) ) { $output = rtrim($output, ", "); // remove trailing comma $output .= ' and '; } // output category name linked to the archive $output .= 'name ) ) . '">'.$category->cat_name.''.$separator; } echo trim($output, $separator); echo "

"; }