• I created a custom archives page which currently lists all posts with date/month headers. I would like to limit the number of posts to, say, 50, and add “Next” and “Previous” buttons at the bottom.

    Here’s the current code:

    <?php
    	// Declare some helper vars
    	$previous_year = $year = 0;
    	$previous_month = $month = 0;
    	$ul_open = false;
    
    	// Get the posts
    	$myposts = get_posts('numberposts=-1&orderby=post_date&order=DESC');
    	?>
    
    <?php foreach($myposts as $post) : ?>	
    
    	<?php
    
    	// Setup the post variables
    	setup_postdata($post);
    
    	$year = mysql2date('Y', $post->post_date);
    	$month = mysql2date('n', $post->post_date);
    	$day = mysql2date('j', $post->post_date);
    
    	?>
    
    	<?php if($year != $previous_year || $month != $previous_month) : ?>
    
    		<?php if($ul_open == true) : ?>
    		</ul>
    
    		<?php endif; ?>
    
    	<h2 class="pagetitle"><?php the_time('F Y'); ?></h2>
    
    		<ul id="fullarchive">
    
    		<?php $ul_open = true; ?>
    
    	<?php endif; ?>
    
    	<?php $previous_year = $year; $previous_month = $month; ?>
    
    			<li>
    
    	<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>  
    
    			</li>
    
    		<?php endforeach; ?>
    			</ul>

    Any ideas how to edit the code? Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Instead of get_posts couldn’t you use

    global $query_string;
    query_posts($query_string . '&numberposts=-1&orderby=post_date&order=DESC');

    And then make sure you have the next_posts_link and previous_posts_link constructs in your template.

    Thread Starter multiplier

    (@multiplier)

    Thanks Michael. Actually according to the Codex, it looks like get_posts will take some of the same arguments as query_posts, so I was able to limit the number of entries like this –

    $myposts = get_posts('orderby=post_date&order=DESC&showposts=50');

    The issue is that I don’t know where in the template to insert the next_posts/previous_posts hooks – any ideas?

    Look at the WordPress Default Theme’s index.php for an example.

    Thread Starter multiplier

    (@multiplier)

    I know in index.php, the pagination traditionally goes between the endwhile and the else. But the example above is not a traditional Loop and there is no endwhile, so I’m still not sure where to insert the pagination. Everywhere I’ve tried inserting it has broken the page.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘adding pagination to custom archives page?’ is closed to new replies.