When I'm on archives pages I am using the code below to query posts. In my theme options to_count_home calls the number of posts.
WordPress isn't generating the correct number of pages based on posts_per_page. Instead it is generating pages based on the number of posts per page I have selected in my default WordPress settings. For example, if I have 10 posts per page in the settings then set posts_per_page in the code as 5, when I go to the second page (which should have 5 posts on it) I get a 404 error.
Here is the code I'm using:
<?php
$per_page = get_option('to_count_home');
query_posts("posts_per_page={$per_page}");
if (have_posts())
?>