Support » Themes and Templates » how to get an archive link based on post date

  • Resolved calvinc


    i’m busy writing my own theme and i’d like to get a link to the archives based on the post date.

    i’ve got the following (><?php the_time(‘jS F, Y’) ?>), which doesn’t give the right path nor the correct date format – missing /.

    then i dug a bit into wordpress and came up with the following:
    $tempURL = get_day_link(the_time(‘Y’),the_time(‘m’),the_time(‘j’));
    $tempDate = sprintf(‘%1$d-%2$02d-%3$02d 00:00:00’, the_time(‘Y’), the_time(‘m’), the_time(‘j’));
    $tempText = mysql2date(‘Y/m/d’, $tempDate);
    echo get_archives_link($tempURL, $tempText, ‘html’, ”, ”);
    but this time it gives the correct path but the date is todays date and not related to the post.

    can anybody help me with this please.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Samuel Wood (Otto)

    (@otto42) Admin

    I’m not sure what you are trying to do, exactly, but all you need to do is to call one of these functions:

    get_day_link($year, $month, $day)
    get_month_link($year, $month)

    You don’t need all that other crap to get a link.

    thanks, I didn’t realize the variables were still within scope. pretty new to php.

    the $year and $day work 100% but the $month always returns 01 for each post, and they certainly weren’t posted in january.


    anybody else wanting to do this you have to do the following:
    <?php echo get_day_link(get_post_time(‘Y’), get_post_time(‘m’), get_post_time(‘j’)); ?>

    NOTHING else will work!



    Hi Calvin,

    Most likely you will not checking this post, but just in case. I need to do a similar thing. How can it be done in a WP Page (not in any php)? thx.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘how to get an archive link based on post date’ is closed to new replies.