[resolved] how to get an archive link based on post date (5 posts)

  1. calvinc
    Posted 9 years ago #

    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.

  2. 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.

  3. calvinc
    Posted 9 years ago #

    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.


  4. calvinc
    Posted 9 years ago #

    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!

  5. misty9
    Posted 8 years ago #

    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.


Topic Closed

This topic has been closed to new replies.

About this Topic