I am working my way through customizing the Worpress default theme. I came up against an issue of formatting archive links.
The default theme uses wp_get_archives
function defined in general-template.php
. The output of the function is customisable, but not customisable enough for me.
I can achieve everything I want to do by basically reimplementing that particular function in my functions.php
file but I am hesitant to do so as it introduces regression issues as Wordpress gets updated. wp_get_archives
does all the lower level stuff like constructs a DB query and caches the DB results. I would really like to avoid doing this if I can.
Another way open to me is to create get_archives_link
filter at which point the link HTML is already formatted and I would need to run a bunch of regex to make sense of it. This seems completely backwards to me as it would completely kill the performance.
Here is exactly what I want output:
<li><a href="/year/01">JAN</a></li>
<li class="current"><a href="/year/02">FEB</a></li>
<li>MAR</li> <!--no blog entries this month-->
...
As far as I can see wp_get_archives
has hardcoded text of the anchor:
$text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);
Then thre is an issue of adding months that have no posts, I would much rather prefer to do that without parsing the text. Then I would need to add the current class (when the URL is something like .../2009/12).
I've actually got a solution that works using a copy of wp_get_archives
. Is this the way to do things and do I worry too much about nothing?
EDIT I guess the real question is is it OK to write your oen SQL for a Wordpress theme? And if it is, what is the best practice in doing so.