Overriding wp_get_archives for a theme in Wordpress

I am working on setting a default Worpress theme. I ran into the problem of formatting archive links.

The default theme uses the function wp_get_archivesdefined in general-template.php. The function output is configurable but not configurable enough for me.

I can achieve everything that I want to do, basically overriding this particular function in my file functions.php, but I hesitate to do this because it introduces regression problems when updating Wordpress. wp_get_archivesdoes all the elements of a lower level, for example, builds a database query and caches database results. I would really like to avoid this if I can.

Another way for me is to create a filter get_archives_link, after which the HTML link is already formatted, and I will need to run a bunch of regular expressions to figure this out. It seems to me completely the opposite, as it will completely destroy performance.

Here is what I need for the 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, the wp_get_archivesanchor code is hard:

$text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);

Then the question arises of adding months that have no messages, I would prefer to do it indiscriminately. Then I will need to add the current class (when the URL looks like ... / 2009/12).

I have a solution that works with a copy wp_get_archives. Is this a way to do something and am I too worried about anything?

, , SQL Wordpress? , .

+3
1

functions.php , .

. , Wordpress, Wordpress, functions.php.

, , . style.css 2 ( ) .

Theme Name: WordPress Default

Wordpress , .

+1

Source: https://habr.com/ru/post/1728159/


All Articles