0

我只想显示我的博客文章的类别,但对于某些类别(特别是如果它们独立,最后一点会被修剪掉~“音乐”变成“Mu”,“冒险”变成“冒险”。 ..有什么帮助吗?拜托!

// 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>';

}
4

1 回答 1

2

您将参数传递给 rtrim 调用$separator,该参数具有该值</div><div class="categz">,因此当执行以下语句时,它将chars从您的字符串中删除以下内容。div<>clastegz

rtrim( str_replace( '<br />',  $separator, $cats ) ), $separator );

解决方法,去掉第二个参数rtrim

于 2013-07-12T09:39:10.413 回答