views:

500

answers:

2

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.

A: 

If you define it in your functions.php file within your active theme, there shouldn't usually be a regression issue.

However, this isn't quite true when changing the default theme. If you were then to upgrade Wordpress by uploading the entire wordpress source, it would overwrite functions.php.

To solve this, duplicate the entire folder containing the Default theme. In the new copy, edit style.css and change line 2 (theme name) to a new theme name.

Theme Name: WordPress Default

Wordpress will now see an extra theme, which you can edit to your hearts' content.

adam
Fair enough, i've made it a separate theme so it doesn't get zapped when updating Worpress. The regression issues that I had in mind would be changes in database schema or caching interface. As far as I can understand SQL is being cleaned up in the filter so it's unlikely that there would be SQL injection related security changes.
Igor Zevaka
A: 

Here's one method of doing it without touching the core codes:

http://www.keetee.com/how-to-customize-the-date-format-for-wp_get_archives/comment-page-1/#comment-3350

Giraldi Maggio