Wp_list_categoriesの最後のリンクから最後の区切り文字(通常は<br/>
タグですが、 "//"に変更)を削除しようとしています。
基本的に私はこれが欲しい:
カテゴリー1 //カテゴリー2 //カテゴリー3 //
このようになります。
カテゴリー1 //カテゴリー2 //カテゴリー3
これが私が使っている現在のコードです:
<?php
$cat_array = array();
$args = array(
'author' => get_the_author_meta('id'),
'showposts' => -1,
'caller_get_posts' => 1
);
$author_posts = get_posts($args);
if ( $author_posts ) {
foreach ($author_posts as $author_post ) {
foreach(get_the_category($author_post->ID) as $category) {
$cat_array[$category->term_id] = $category->term_id;
}
}
}
$cat_ids = implode(',', $cat_array);
echo strtr(wp_list_categories('include='.$cat_ids.'&title_li=&style=none&echo=0'),array('<br />'=>' // '));
?>
最後の行をこれに変更します。
$output = strtr( wp_list_categories( 'include='.$cat_ids.'&title_li=&style=none&echo=0' ), array( '<br />' => ' // ' ) );
echo preg_replace( '@\s//\s\n$@', '', $output );
あなたはそこで起こっているロタストリング処理を得ました。結果をリストとして出力した方がいいかもしれません。
wp_list_categories('include='.$cat_ids.'&title_li=');
そしてそれをcssでスタイリングする:
li.cat-item { list-style-type: none; display: inline; }
li.cat-item:before { content: " // "; }
li.cat-item:first-child:before { content: none; }
考慮すべきもう1つの選択肢...
もう一つの選択肢は、爆発 - >ポップ - >爆縮...
$output = explode( '<br />', wp_list_categories( 'include='.$cat_ids.'&title_li=&style=none&echo=0' ) );
array_pop($output);
echo implode(' // ',$output);