Making counts appear inside wordpress categories links

Posted by Doug on July 05, 2009
Technology

On the theme I’m using (Big City), the wordpress default for showing counts next to categories looks awful. The lines break after the link, so it will say something like “Technology ::break:: (31)”. The solution I found was basically just to hack the code where it prints the count, and move that up. This stuff is hard-coded in wordress, and I couldn’t find a CSS solution to my problem (I do suck at CSS, but that’s another story).

Here are the changes as of WP 2.8.

In “general-template.php”, locate the lines that say

$after = ' ('.$arcresult->posts.')' . $afterafter;

and change them to

$text .= <...>

There are a number of such lines, so this will make them all consistent. I think I counted 4 such changes.

The other change to make is in “classes.php”.  Break line 1336 (which looked something like this before I got to it)

$link .= $cat_name . "</a>";

So that it becomes

$link .= $cat_name;
$link .= "</a>";

Now move up this block between those two lines:

if ( isset($show_count) && $show_count )
 $link .= ' (' . intval($category->count) . ')';

This will change your formatting slightly if you were using the feed code, and I don’t have a good answer for you on that.

No comments yet.

Leave a comment

WP_Big_City