List WordPress Child Categories with a Pipe Divider and Links

Today I had a need to create a list of WordPress child category links in a theme. Each category in the list needed a pipe divider, except the last one. So my categories will look like:

Category 1 | Category 2 | Category 3

I looked into using wp_list_pages, but that didn’t quite get the job done. So, here is what I came up with:

Categories: 
cat_name;
	$category_ID = $category->term_id;
	$category_link = get_category_link ($category_ID);
	echo '' . $category_name . '';
	if ( $i < $total_number_of_categories ) {
		echo ' | ';
	}
	$i++;
} ?>

Is there a better way to do this?

Posted in ,

Toby Cryns

Toby Cryns is a freelance CTO, expert WordPress consultant, and teacher.

He offers free advice to improve your freelance biz.

He also publishes small droppings every now and then to twitter.com/tobycryns and twitter.com/themightymo

Follow Toby's contributions on Github and WP.org.

1 Comments

  1. sinzoo on November 30, 2011 at 3:33 pm

    Worked like a charm 🙂 Thanx!