我只想显示我的博客帖子的类别,但是对于某些类别(特别是如果它们独立,最后一点被删除〜“音乐”变成“Mu”,“冒险”变成“ Adventur“......有什么帮助吗?拜托!
// Category boxes :P
function showcatz() {
global $post;
echo '<div class="categz_wrapper"><div class="categz">';
// get the category IDs assigned to post
$categories = wp_get_post_categories( $post->ID, array( 'fields' => 'ids' ) );
// separator between links
$separator = '</div><div class="categz"> ';
if ( $categories ) {
// List categories
$cat_ids = implode( ',' , $categories );
// Remove ONE category from the list
$kill = array("411,", "411");
$killit = str_replace($kill, "", $cat_ids);
$cats = wp_list_categories( 'title_li=&style=none&echo=0&include=' . $killit);
$cats = rtrim( trim( str_replace( '<br />', $separator, $cats ) ), $separator );
// Only show categories if there is any
if ( $killit ) { echo $cats; }
}
echo '</div></div>';
}
答案 0 :(得分:2)
将参数传递给名为$separator
的rtrim,其值为</div><div class="categz">
,因此当执行以下语句时,它将从您的字符串中删除以下chars
。 div<>clastegz
rtrim( str_replace( '<br />', $separator, $cats ) ), $separator );
解决方案,将第二个参数移至rtrim