Tôi đang cố xóa dấu tách cuối cùng (thông thường là thẻ <br/>
nhưng tôi đã thay đổi thành "//") từ liên kết cuối cùng từ wp_list_.
Về cơ bản tôi muốn điều này:
Loại 1 // Loại 2 // Loại 3 //
trông như thế này:
Loại 1 // Loại 2 // Loại 3
Đây là mã hiện tại tôi đang sử dụng:
<?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 />'=>' // '));
?>
Thay đổi dòng cuối cùng thành này:
$output = strtr( wp_list_categories( 'include='.$cat_ids.'&title_li=&style=none&echo=0' ), array( '<br />' => ' // ' ) );
echo preg_replace( '@\s//\s\[email protected]', '', $output );
Bạn có một chuỗi xử lý lotta đang diễn ra ở đó. Bạn có thể tốt hơn nên đưa ra kết quả dưới dạng danh sách
wp_list_categories('include='.$cat_ids.'&title_li=');
và tạo kiểu với css:
li.cat-item { list-style-type: none; display: inline; }
li.cat-item:before { content: " // "; }
li.cat-item:first-child:before { content: none; }
Chỉ là một cách khác để xem xét ...
Một tùy chọn khác, phát nổ -> pop -> nổ ...
$output = explode( '<br />', wp_list_categories( 'include='.$cat_ids.'&title_li=&style=none&echo=0' ) );
array_pop($output);
echo implode(' // ',$output);