Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

2 Answers 2

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>';
endwhile;

echo '</ul>';
wp_reset_query();

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
add comment

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
add comment

Your Answer

 
discard

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.