Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to figure out a way to do a loop / archive page with posts organized by month. So where each page displays post from 1 month. Then the previous and next links would be labeled February 2011 and April 2011, for example.

I'm thinking it would possibly use the date.php file, but I feel like I may run into problems when paginating from one year to the next...

Anyone have any ideas, or documentation on where to look further?


share|improve this question

1 Answer 1

I think this is not very hard to do. If you have currently have paginated date-based archives you can just disable paging when you are in a month overview:

add_action( 'pre_get_posts', 'wpse12983_pre_get_posts' );
function wpse12983_pre_get_posts( &$wp_query )
    if ( $wp_query->is_month() ) {
        $wp_query->set( 'nopaging', true );

You can use get_month_link() to get links to the adjacent months. If you want to skip months without posts you can call get_previous_post() at the beginning of the loop and get_next_post() at the end (or you set the global $post variable yourself before you call these functions - they don't accept a post argument). Extract the dates from these posts and pass them to get_month_link().

share|improve this answer

Your Answer


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