- Author had a File in an Envato Bundle
- Author was Featured
- Bought between 1 and 9 items
- Europe
- Exclusive Author
- Has been a member for 2-3 years
- Item was Featured
- Referred between 100 and 199 users
<ul>
<li class="cat-item cat-item-5 first-child"><a href="site-url/?cat=5" title="View all posts filed under cat 1">cat 1</a> (1)</li>
</ul>
to
<ul>
<li class="cat-item cat-item-5 first-child"><a href="site-url/?cat=5" title="View all posts filed under cat 1">cat 1<span class="post-count">(1)</span></a></li>
</ul>
and for the other widgets that have a post count? any ideas? thanks and please help ! 
- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Interviewed on the Envato Notes blog
- Author was Featured
- Item was Featured
- Beta Tester
- Author had a File in an Envato Bundle
- Author had a Free File of the Month
Hi,
to customize the default widgets unfortunately there aren’t good filters available. What I did in my themes is for example:
unregister_widget(‘WP_Widget_Archives’);
register_widget(‘Duotive_Widget_Archives’);
^ That should be done within a widget_init hook.
Then I just copied the original class of the widget to override from wp-includes/default-widgets.php and renamed the class name to match the new name I registered.
Doing this you can basically edit whatever you want of the widget without getting crazy with filters and similar…
Parker
I suppose you could use wp_count_posts in your template. It could filter the number of posts being published, drafts etc and chose post types.
I’m not quite sure if it filters categories because your code snippet lead me to that suggestion.
- Author had a File in an Envato Bundle
- Author was Featured
- Bought between 1 and 9 items
- Europe
- Exclusive Author
- Has been a member for 2-3 years
- Item was Featured
- Referred between 100 and 199 users
the problem is i do not want to rewrite all the widgets because the theme we are making is already complicated as hell and this will take a lot of my time. I found something:
function add_span_cat_count($links) {
$links = str_replace(' (', ' <span>(', $links);
$links = str_replace(')', ')</span>', $links);
return $links;
}
add_filter('wp_list_categories', 'add_span_cat_count');
but this adds the span outsite of the anchor. i want it inside.- Author had a File in an Envato Bundle
- Author was Featured
- Bought between 1 and 9 items
- Europe
- Exclusive Author
- Has been a member for 2-3 years
- Item was Featured
- Referred between 100 and 199 users
@mpforce i am talking about a filter for the default widgets, i do not want to rewrite them. thanks anyway 
Try replacing your snippet’s 2 lines with these:
$links = str_replace('<a>', '</a><a><span> (', $links);
$links = str_replace('</span></a>', ') ', $links);
Haven’t tried it myself, but with some corrections could work.
P.S. Line 1, the closing anchor tag shouldnt be there, it’s just a bug in the text editor.
- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Interviewed on the Envato Notes blog
- Author was Featured
- Item was Featured
- Beta Tester
- Author had a File in an Envato Bundle
- Author had a Free File of the Month
I took 10 minutes to customize all the default widgets…
I extended the original class with the new one, so I only needed to override the main widget function that handles the output. I don’t see how this process has anything to do with the theme’s complexity… it’s just a manual filter 
Parker
- Author had a File in an Envato Bundle
- Author was Featured
- Bought between 1 and 9 items
- Europe
- Exclusive Author
- Has been a member for 2-3 years
- Item was Featured
- Referred between 100 and 199 users
@mpforce – thanks, that is exatcly what i am using.
@parker – and what do i do when wordpress upgrades the widgets?
nevertheless, or the solution you are saying is simple and i do not see how to do it or i am tired – i think both 
- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Interviewed on the Envato Notes blog
- Author was Featured
- Item was Featured
- Beta Tester
- Author had a File in an Envato Bundle
- Author had a Free File of the Month
duotive said
@mpforce – thanks, that is exatcly what i am using.
@parker – and what do i do when wordpress upgrades the widgets?nevertheless, or the solution you are saying is simple and i do not see how to do it or i am tired – i think both
![]()
Well, you have to extend/duplicate (your choice) the classes within your framework, you don’t touch any WP file… updates of WP don’t affect this. If you just duplicate the class, your widget will work like that also if WP will come with a totally new updated widget… this is like creating a custom widget exactly like the default ones.
I faced your same problem trying to customize the widgets html output, but believe me I didn’t find any way to make that with filters, because there isn’t any filter for this…
Parker
- Author had a File in an Envato Bundle
- Author was Featured
- Bought between 1 and 9 items
- Europe
- Exclusive Author
- Has been a member for 2-3 years
- Item was Featured
- Referred between 100 and 199 users
<?php wp_get_archives(apply_filters('widget_archives_args', array('type' ?> 'monthly', 'show_post_count' => $c))); ?>
Let’s say i add and rewrite the widgets with my own, i still need a filter for wp_get_archives to add a span arround the post count. And ps, i solved the problem with the categories, i just used as i found it with the span outsite, but now i need the same thing for the archives and cannot find the correct filter to hook to.