GraphicRiver

default wordpress widget filter

2945 posts
  • Author had a File in an Envato Bundle
  • Bought between 1 and 9 items
  • Elite Author
  • Europe
  • Exclusive Author
  • Has been a member for 2-3 years
  • Referred between 100 and 199 users
+2 more
duotive says
hey. and ideas how to get the post count inside of the anchor with a span? something like from:
<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 ! :D
3256 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Beta Tester
  • Author had a File in an Envato Bundle
  • Author had a Free File of the Month
+4 more
ParkerAndKent says

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

19 posts
  • Bought between 50 and 99 items
  • Bulgaria
  • Exclusive Author
  • Has been a member for 1-2 years
mpforce says

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.

2945 posts
  • Author had a File in an Envato Bundle
  • Bought between 1 and 9 items
  • Elite Author
  • Europe
  • Exclusive Author
  • Has been a member for 2-3 years
  • Referred between 100 and 199 users
+2 more
duotive says
Hey. Thanks :) 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.
2945 posts
  • Author had a File in an Envato Bundle
  • Bought between 1 and 9 items
  • Elite Author
  • Europe
  • Exclusive Author
  • Has been a member for 2-3 years
  • Referred between 100 and 199 users
+2 more
duotive says

@mpforce i am talking about a filter for the default widgets, i do not want to rewrite them. thanks anyway :)

19 posts
  • Bought between 50 and 99 items
  • Bulgaria
  • Exclusive Author
  • Has been a member for 1-2 years
mpforce says

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.

3256 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Beta Tester
  • Author had a File in an Envato Bundle
  • Author had a Free File of the Month
+4 more
ParkerAndKent says

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

2945 posts
  • Author had a File in an Envato Bundle
  • Bought between 1 and 9 items
  • Elite Author
  • Europe
  • Exclusive Author
  • Has been a member for 2-3 years
  • Referred between 100 and 199 users
+2 more
duotive says

@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 :(

3256 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Beta Tester
  • Author had a File in an Envato Bundle
  • Author had a Free File of the Month
+4 more
ParkerAndKent says
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

2945 posts
  • Author had a File in an Envato Bundle
  • Bought between 1 and 9 items
  • Elite Author
  • Europe
  • Exclusive Author
  • Has been a member for 2-3 years
  • Referred between 100 and 199 users
+2 more
duotive says
The points you said above are good but that sill does not help me with this issue:
<?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.
by
by
by
by
by