I'm building a site for a magazine using WP and am needing to display a month of posts at a time.

How would I make the next_posts_link(); and previous_posts_link(); functions return results, shorted as one month per page?

If I can't do it via those functions, how would I make the front page display in an archive-like mode?


2 Answers 2


You have to modify the query that selects the posts to select by month. This bit of code placed in the template will get the page number and subtract that from the current month.


$page = get_query_var('paged') ? get_query_var('paged') : 1;
$subtractor = $page-1;
$date = date("Y-m-d H:i:s");
$current_month = date('n', strtotime($date.'-'.$subtractor.'months'));
$current_year = date('Y', strtotime($date.'-'.$subtractor.'months'));

if (have_posts()) :
while (have_posts()) : the_post(); // rest of the loop below

Ultimately this is probably best hooked into pre_get_posts to keep it out of the template.

You'd have to make your own pagination links as well, something like:

    echo '<a href="/page/'.($page-1).'/">next</a>';

echo '<a href="/page/'.($page+1).'/">prev</a>';

of course, you'd have to figure out how far back the posts go to know when to stop providing a previous month link, hmm...


I'm not sure if this is what you're looking for; however, this may help out.

 foreach (get_the_category() as $cat) {
 $arch_date_id = $cat->cat_ID;

 global $post;
 $query = 'numberposts=-1&category=' . $arch_date_id . '&orderby=date&order=DESC';
 $myposts =  get_posts();
      foreach($myposts as $post) {
           $year = get_the_time('Y');
           $groups[] = $year;

 $groups = array_values(array_unique($groups));
 $qi = $groups[0]; 
 $query = 'cat=' . $arch_date_id . '&year=' . $qi . '&orderby=date&order=DESC&posts_per_page=-1';
 echo '<h3>' . $qi . '</h3>';
 while (have_posts()) : the_post();
<? the_date('F j','<h3>','</h3>');?>
<? the_title();?><br />
<? endwhile; ?>
  • Uh, not really. This seems to just be a loop that outputs each category by year, completely not what I was asking for...
    – aendra
    Commented May 7, 2011 at 0:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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