Saya mencoba menghapus pemisah terakhir (biasanya tag <br/>
tapi saya mengubahnya menjadi "//") dari tautan terakhir dari wp_list_categories.
Pada dasarnya saya menginginkan ini:
Kategori 1 // Kategori 2 // Kategori 3 //
agar terlihat seperti ini:
Kategori 1 // Kategori 2 // Kategori 3
Berikut kode saat ini yang saya gunakan:
<?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 />'=>' // '));
?>
Ubah baris terakhir ke ini:
$output = strtr( wp_list_categories( 'include='.$cat_ids.'&title_li=&style=none&echo=0' ), array( '<br />' => ' // ' ) );
echo preg_replace( '@\s//\s\[email protected]', '', $output );
Anda punya pemrosesan string lotta yang terjadi di sana. Anda mungkin lebih baik menampilkan hasilnya sebagai daftar
wp_list_categories('include='.$cat_ids.'&title_li=');
dan menatanya dengan css:
li.cat-item { list-style-type: none; display: inline; }
li.cat-item:before { content: " // "; }
li.cat-item:first-child:before { content: none; }
Hanya alternatif lain untuk dipertimbangkan ...
Opsi lain, meledak -> pop -> implode ...
$output = explode( '<br />', wp_list_categories( 'include='.$cat_ids.'&title_li=&style=none&echo=0' ) );
array_pop($output);
echo implode(' // ',$output);