Combing Years Within Archive Widget

I currently have the standard archive widget running in a sidebar producing a list of years using the code:

function my_limit_archives($args){
$args[‘type’] = yearly;
$args[‘show_post_count’] = true;
return $args;
}
add_filter( ‘widget_archives_args’, ‘my_limit_archives’ );

Which produces a yearly list (with post counts): 2018 (1), 2017 (2), 2016 (3), 2015 (4), 2014 (5), 2013 (6), 2012 (7), 2011 (8), 2010 (10).

This list will obviously continue growing year on year down my site and look a bit unattractive after a while.

What I’m hoping to do is limit the list by grouping the years after a certain time along with their post counts, so the list that looks like: 2018 (1), 2017 (2), 2016 (3), 2015 (4), 2014 (5), 2013 – 2010 (31).

I know I can add $args[‘limit’] = 5; to the function call to limit the years, but that doesn’t create the group but simply cut them off.

I’m afraid my knowledge of php becomes lacking at this point – how can I go about creating the combined group?

MTIA – Chris

Read more here:: Combing Years Within Archive Widget

Leave a Reply

Your email address will not be published. Required fields are marked *