List categories as text in a headline, with commas
-
Greetings. I playing with a php function to display a list of up to 3 categories (Advertising, Design, Publishing) in a headline, with commas after all but the last category item. I figured out how to display the categories with commas but can’t figure out how to eliminate the comma after the last category item.
Here are my PHP efforts so far:
<h4> <?php $taxterms = get_the_terms($post->ID, 'portfolio_category' ); $taxcount = count($taxterms); if($taxcount == 1){ if ($taxterms) foreach ($taxterms as $taxterm){ echo $taxterm->name . ' '; } }else if($taxcount > 1){ if ($taxterms) foreach ($taxterms as $taxterm){ echo $taxterm->name . ', '; } } ?> </h4>
Here is how it looks on the site: https://www.lcomdesigns.com/portfolio/teaching-the-levees/
Any help eliminating that last comma is appreciated.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘List categories as text in a headline, with commas’ is closed to new replies.