您可以稍微更改代码:
$taxonomy = \'country\';
$terms=get_the_terms($post->ID,$taxonomy);
if($terms) {
echo \'<h1>Holiday \';
$total_count = count($terms);
$country_count = 1;
foreach( $terms as $termcountry ) {
if ($country_count = 1){
echo \'in \'.$termcountry->name;
}else{
if ($total_count = 2){
echo \' And \'.$termcountry->name;
}else{
echo \', \'.$termcountry->name;
}
}
$country_count = $country_count + 1 ;
}
echo \'</h1>\';
}
这将在一个术语的情况下输出:
<h1>Holiday in Spain</h1>
如果有两个术语:
<h1>Holiday in Spain And Japan</h1>
如果超过两个术语:
<h1>Holiday in Spain, Japan, England</h1>
希望这有帮助