Support » Themes and Templates » Change wp_get_archives date format?

  • At the moment, wp_get_archives('type=monthly') gives a list like this:

    • April 2006 (1)
    • May 2006 (2)

    Now is there a way to change the format of these dates? For example, have them display this instead:

    • 2006, April [1]
    • 2006, May [2]

    What I’m trying to do, is to produce a properly localized (Chinese) weblog; but I’m stuck here at the date order.

Viewing 8 replies - 1 through 8 (of 8 total)
  • akc


    Apparently this is not possible in 2.0.x. And the bug tracker shows its priority is “lowest”. That’s embarrassing…. See



    If you want to do a bit of hacking, you can change it in the code directly. The file to edit is ‘template-functions-general.php’ found in the ‘wp-=includes’ directory. You’ll want to change the function called ‘get_archives’. The lines you should fix are the following:

    $text = sprintf(‘%s %d’, $month[zeroise($arcresult->month,2)], $arcresult->year);

    You will find it listed twice on lines 337 and 340.

    Try changing it to:

    $text = sprintf(‘%d, %s’, $arcresult->year, $month[zeroise($arcresult->month,2)]);

    That should word I think… ;p



    Thanks, that works.

    I’ll just add:

    ‘%d年%s’ supplies the year suffix. This assumes the month name has been properly localised to n月, where n is a Chinese or Japanese numeral. Lets hope this kind of hardcoding will soon go away, though.



    Another one:

    $text = sprintf(‘%d年%s月’, $arcresult->year, $arcresult->month);

    gives nnnn年nn月, where each n is an Arabic numeral.



    I didn’t realise that you could have ‘nian’ and ‘ye’ in the vars and output them too. Cool! You could probably write a small function that will convert ‘1,2,3…’ to ‘yi, er, san…’.

    then you would get: 二〇〇六年六月

    BTW, could you mark this post resolved.



    alrescha appears to be a theme localizer, so the hacking approach won’t work for him/her if the goal is to distribute ready-to-use Chinese themes.

    (OT: In the name of World Domination, I think WP needs to up this bug’s priority a notch or two.)

    I’m trying to alter the template-functions-general.php file to ADD the date to a post-by-post listing but am having a hard time. Here’s what I have so far:

    elseif ( 'postbypost' == $type ) {

    $arcresults = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_date < '$now' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);

    if ( $arcresults ) {
    foreach ( $arcresults as $arcresult ) {
    if ( $arcresult->post_date != '0000-00-00 00:00:00' ) {
    $date = sprintf("%02d-%02d-%d", $arcresult->month, $arcresult->dayofmonth, $arcresult->year);
    $url = get_permalink($arcresult);
    $arc_title = $arcresult->post_title;
    if ( $arc_title )
    $text = strip_tags($arc_title, $date);
    $text = $arcresult->ID . $date;
    echo get_archives_link($url, $text . " (" . $date . ")", $format, $before, $after);

    which gives me listings such as:
    Post title blah blah blah. (00-00-0)

    with all the zeros for the date. How can I use the daily code of
    $dateresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS year, MONTH(post_date) AS month, DAYOFMONTH(post_date) AS dayofmonth` FROM $wpdb->posts WHERE post_date < ‘$now’ AND post_date != ‘0000-00-00 00:00:00’ AND post_status = ‘publish’ ORDER BY post_date DESC” . $limit);’

    in my script to pull the date for each listing? Thanks in advance!

    I just made it SORT OF work: You can see it here

    I created a second variable just to try to use the basic post_date return and it did work:

    $shortdate = $arcresult->post_date;
    echo get_archives_link($url, $text . " (" . $shortdate . ")", $format, $before, $after);

    but the format is not pleasing. Any ideas on how to style that info so (2006-08-23 22:32:27) becomes (August 23, 2006) or at least (08-23-2006) although the first is greatly preferable.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Change wp_get_archives date format?’ is closed to new replies.