Foreach loop seperated by commas, but last value preceded by amperstand
-
I have the following code:
<?php $terms = get_the_terms( $post->ID , 'writer' ); if($terms) { foreach( $terms as $term ) { echo $term->name; } } ?>
I need to output my terms as a comma-separated list with the last term being preceded by an ampersand rather than a comma. So I want something like this:
Author 1, Author 2 & Author 3
For a complicated reason I won’t waste your time with, I can’t rely on CSS to do this, so I need an alternative.
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘Foreach loop seperated by commas, but last value preceded by amperstand’ is closed to new replies.