WordPress.org

Ready to get started?Download WordPress

Forums

Return month/year on archive pages (2 posts)

  1. C W
    Member
    Posted 2 years ago #

    I'm creating my own archive.php for a theme and would like to have as the page heading "Articles from December 2011" or "Articles from 2010" etc.

    In the Twenty Eleven theme, it's produced via:

    <?php if ( is_day() ) : ?>
    	<?php printf( __( 'Daily Archives: %s', 'twentyeleven' ), '<span>' . get_the_date() . '</span>' ); ?>
    	<?php elseif ( is_month() ) : ?>
    	<?php printf( __( 'Monthly Archives: %s', 'twentyeleven' ), '<span>' . get_the_date( _x( 'F Y', 'monthly archives date format', 'twentyeleven' ) ) . '</span>' ); ?>
    	<?php elseif ( is_year() ) : ?>
    	<?php printf( __( 'Yearly Archives: %s', 'twentyeleven' ), '<span>' . get_the_date( _x( 'Y', 'yearly archives date format', 'twentyeleven' ) ) . '</span>' ); ?>
    	<?php else : ?>
    	<?php _e( 'Blog Archives', 'twentyeleven' ); ?>
    	<?php endif; ?>

    ... but I can't seem to reproduce this in my own theme: it comes out every time as "May 2012" or "2012" regardless of which archive I'm pulling (i.e. the current date instead of the date of the archive itself). How would I produce this properly?

  2. SiRa-wp
    Member
    Posted 2 years ago #

    Hey there,
    your piece of code will only work for a child theme of twentyeleven. The call you are looking for is this http://codex.wordpress.org/Template_Tags/wp_get_archives. If you find that in twentyeleven and see how its used, you'll be able to make your theme display the archives the way you want to.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.