Skip to content

Instantly share code, notes, and snippets.

@joeyz
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeyz/ad53f779f63678e1ccc4 to your computer and use it in GitHub Desktop.
Save joeyz/ad53f779f63678e1ccc4 to your computer and use it in GitHub Desktop.
Wordpress Pagination for archive page
//Dont forget to set how many items you want on each page in "Settings > Reading > Blog pages show at most"
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
// WP_Query arguments
$args = array (
'pagination' => true,
'paged' => $paged,
'order' => 'ASC'
);
// The Query
$query_events = new WP_Query( $args );
// The Loop
if ( $query_events->have_posts() ) {
while ( $query_events->have_posts() ) {
$query_events->the_post();
?>
//Do some stuff in the loop
<?php
}
} else {
echo 'Nothing going on here boss';
} ?>
<div class="nav-previous alignleft"><?php next_posts_link( 'Later Events' ); ?></div>
<div class="nav-next alignright"><?php previous_posts_link( 'Closer Events' ); ?></div>
<?php // Restore original Post Data
wp_reset_postdata();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment