开发者

Have wp_get_archives return a string with no year in it

Currently I use wp_get_archives to return the year.

I then call it again with the monthly arg to display the months.

开发者_Python百科

It displays similarly to this, though I am not sure it will work when we are in a different year:

2011

April 2011(1)

March 2011(12)

I want a display like this

2012(when we reach it)

December(8)

November(5)

2011

April(1)

March(12)

Where the number in brackets is the months post count.

Obviously this means stripping out the year from the monthly archives. Is this possible? I'd rather not modify core wp functions and do this within the theme, I would also rather not rely on a plugin.

Thank you!


While maybe not the best way to do it, give this a try

$string = wp_get_archives('type=monthly&limit=20&echo=0');
$pattern = ' ((19|20)\d{2}(</a>))';
echo preg_replace($pattern, '\\3', $string);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜