Pagination on archive.php page

I have an archive.php page with the following code:

<?php // Start your custom WP_query
$my_query = new WP_query();

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('posts_per_page' ?> 1, 'paged' => $paged, 'category_name' => 'Casino Slots');
// Assign predefined $args to your query
$my_query->query($args);

// Run your normal loop
if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post();
?> 
Test 
<?php endwhile;
else :
// do stuff for no results
endif;

wp_pagenavi();

// RESET THE QUERY
wp_reset_query();
?>

and it displays the posts fine, but the pagination never shows?

1 Answer
1

I think your issue is that wp_pagenavi() is doing pagination based off of the global $wp_query instance instead instance you created. You should either switch to using query_posts() to replace the global query instead, or use WordPress’ built in paginate_links to output the paging.

Leave a Comment