Skip to content

Instantly share code, notes, and snippets.

@joeke
Created April 23, 2014 20:18
Show Gist options
  • Save joeke/11230825 to your computer and use it in GitHub Desktop.
Save joeke/11230825 to your computer and use it in GitHub Desktop.
Wordpress wp_query pagination
<?php
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$wp_query = new WP_Query(array('post_type' => 'producten','posts_per_page' => 20,'paged' => $paged));
while ($wp_query->have_posts()) : $wp_query->the_post();
// get the template for eacht product column
get_template_part( 'tpl', 'product' );
endwhile;
echo ( paginate_links($args = array(
'base' => site_url().'%_%', // site_url prefix is needed for pagination on homepage
'format' => '?page=%#%',
'total' => $wp_query->max_num_pages,
'current' => $paged,
'show_all' => false,
'end_size' => 2,
'mid_size' => 2,
'prev_next' => true,
'prev_text' => 'Vorige',
'next_text' => 'Volgende',
'type' => 'list',
'add_args' => false,
'add_fragment' => ''
)));
wp_reset_query();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment