3

Is it possible using wp_list_categories set count of post in category in the href?

1
  • 1
    It's possible, with some regular expression jiggery pokery. Some variation on this – vancoder Apr 11 '13 at 18:59
5

Regular expression jiggery pokery identified:

<?php
$categories = wp_list_categories('title_li=&show_count=1&echo=0');
$categories = preg_replace('/<\/a> \(([0-9]+)\)/', ' <span class="count">[\\1]</span></a>', $categories);
echo $categories;
?>
2
  • 2
    nice solution @vancoder, but preg_replace might be a better choice because ereg_replace is deprecated since php 5.3, according to php.net/ereg_replace. – birgire Apr 11 '13 at 19:45
  • @birgire Excellent point, answer updated. – vancoder Apr 11 '13 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.