views:

137

answers:

2

Hi,

I'm trying to remove the last separator (normally a <br/> tag but I changed it to "//") from the last link from wp_list_categories.

Basically I want this:

Category 1 // Category 2 // Category 3 //

to look like this:

Category 1 // Category 2 // Category 3

Here's the current code I'm using:

<?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 />'=>' // '));
?>

Thanks!

A: 

Use trim:

trim(wp_list_categories('include='.$cat_ids.'&title_li=&style=none&echo=0'), '/')

adam
this didn't seem to work, should i be placing this directly after the echo strtr line at the end?
j-man86
A: 

http://wordpress.stackexchange.com/questions/646/wordpress-remove-br-separator-from-last-item-in-wp-list-categories

$output = strtr( wp_list_categories( 'include='.$cat_ids.'&title_li=&style=none&echo=0' ), array( '<br />' => ' // ' ) );
echo preg_replace( '@\s//\s\n$@', '', $output );
j-man86