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

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

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
how would you use this implementation? – GotaloveCode Feb 1 at 10:09
I tried it like this.It dint work which shows am clearly doing it wrong.Some help please @Jan – GotaloveCode Feb 1 at 10:15
@GotaloveCode: Best if you ask a separate question, with code showing what you have tried. And someone else can take a look, as it has been 5 years since I did any serious PHP work. – Jan Fabry Feb 3 at 13:59

Your Answer


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