我已經嘗試了一些修剪等的東西,但沒有任何效果。
也許我犯了一個錯誤,你能幫助我嗎?代碼目前看起來像這樣:
$post = get_post();
$terms = wp_get_post_terms($post->ID, 'genre');
if ($terms)
{
$output = '';
foreach ($terms as $term) {
$output .= '<a href="' . get_term_link($term->slug, 'genre') . '">' . $term->name . '</a>, ';
}
};
echo $output;
uj5u.com熱心網友回復:
嘗試輸入substr_replace($term->name,"",-1),檢查檔案以獲取更多資訊,這應該從最后一個字串中洗掉逗號。
uj5u.com熱心網友回復:
只需添加一個計數器來檢查陣列的最后一項
$post = get_post();
$terms = wp_get_post_terms($post->ID, 'genre');
if ($terms)
{
$output = '';
$i = 0;
foreach ($terms as $term) {
$output .= '<a href="' . get_term_link($term->slug, 'genre') . '">' . $term->name . '</a> ';
$output .= ($i == count($terms) - 1) ? '' : ',';
$i ;
}
};
echo $output;
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/420983.html
標籤:
