WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to show the related (archive) month and year for a post next to its contents, i.e. "Archived in January 2012". Any help / directions is greatly appreciated.

share|improve this question
up vote 0 down vote accepted

Use following code after the loop:

$month_num = get_the_date('n');
$month_txt = get_the_date('F');
$year = get_the_date('Y');

// change 'posts_per_page' to any value you need, '-1' means 'all'
query_posts( 'posts_per_page=-1&monthnum='.$month_num.'&year='.$year );

echo '<p class="">Archived in '.$month_txt.', '.$year.'</p>';
echo '<ul>';

while ( have_posts() ) : the_post();
    echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';

echo '</ul>';

It's not tested, but you got the idea.

share|improve this answer
Great, thanks guys! Wasn't familiar of get_the_date(). – Staffan Estberg Jul 23 '12 at 11:46

Use get_the_time(), get_month_link() and get_year_link():

function wpse_58787_archive_link()
    $Y   = get_the_time( 'Y' ); // year
    $m   = get_the_time( 'm' ); // month as number
    $F   = get_the_time( 'F' ); // month as word

    return 'Archived in <a href="' . get_month_link( $Y, $m ) . '">' . $F . '</a> 
    <a href="' . get_year_link( $Y ) . '">' . $Y . '</a>';

print wpse_58787_archive_link();
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.