category count with style  [ 880 views ]

Goal: fix the categories list

Get the Categories list:

wp_list_categories('sort_column=name&optioncount=1&hierarchical=0&title_li=<h2>Categories</h2>&show_count=1');

The result is not too correct. The count is out of my style.

<ul>	
  <li class="..."><a href=".." title="...">javascript</a> (7)</li>
  <li class="..."><a href=".." title="...">oracle</a> (1)</li>
  <li class="..."><a href=".." title="...">web trick</a> (1)</li>
  <li class="..."><a href=".." title="...">wordpress</a> (6)</li>
</ul>

To correct this I will wrap the count into a span and I can stylise that after.
Add a new filter to the category list creator. Insert this code to the end of the functions.php file.

add_filter('wp_list_categories', 'cat_count_span');
function cat_count_span($links) {
  $links = str_replace('</a> (', '</a> <span>(', $links);
  $links = str_replace(')', ')</span>', $links);
  return $links;
}

For the correct functioning we need to check the wp-setting.php file. In the Load early WordPress files section be sure the plugin.php is the first like here:

...
// Load early WordPress files.
require( ABSPATH . WPINC . '/plugin.php' );
require( ABSPATH . WPINC . '/functions.php' );
...

the result is:

<ul>	
  <li class="..."><a href=".." title="...">javascript</a> <span>(7)</span></li>
  <li class="..."><a href=".." title="...">oracle</a> <span>(1)</span></li>
  <li class="..."><a href=".." title="...">web trick</a> <span>(1)</span></li>
  <li class="..."><a href=".." title="...">wordpress</a> <span>(6)</span></li>
</ul>

I can use a style now to fix the problem.

sources: correction, fix filter error

#sidebar a { color:#fff; } #sidebar ul ul li { color: #DEF585; } #sidebar h2 { color: #fff; } #sidebar ul p, #sidebar ul select { color: #BEDDBE; } #backfly { background: url(images/golfBallWallPaper.jpg) left bottom fixed repeat-x #65a51d; }