ID ); $separator = ', '; $output = ''; if ( $categories ) { echo '

'; echo '' . esc_html_x( "Published in", "Published in post category", "period" ) . ' '; 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 .= ' ' . esc_html_x( 'and', 'category, category, AND category', 'period' ) . ' '; } $output .= 'name ) ) . '">' . esc_html( $category->cat_name ) . '' . $separator; } echo trim( $output, $separator ); echo "

"; }