WordPress.org

Ready to get started?Download WordPress

Forums

Pagination breaks when query_posts is used with a custom value of posts_per_page (1 post)

  1. mepro
    Member
    Posted 2 years ago #

    I have searched for answers a lot, but haven't found a solution that can fix the pagination problem on WordPress 3.3.1. Most of the solutions are obsolete and hence they dont work any more. I tried to use a custom number for posts_per_page and its breaking the pagination. I am using the default "Twenty Ten" theme. I also tried following codes:

    //Code 1

    query_posts( array( 'posts_per_page' => 3, 'paged' => get_query_var('paged') ) );

    //Code 2

    $args = array(
                       'posts_per_page' => 3,
                       'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
                       );
    query_posts($args);

    I placed the above codes in archive.php page of Twenty Ten theme, just above the following code:

    if ( have_posts() )
    		the_post();

    I have 14 articles. What I noticed is that once I paginate to the second page, it shows me a 404 error when I try to paginate to the third page. The Reading options is set to 10 posts at a time & I think this is the reason, it lets me paginate only the first page as 14 articles @10 articles per page would consume only 2 pages.

    I want to be able to do this control/change pagination from within the theme, as I may not have control over the settings of admin panel or I can't ask the setting to be changed. Please help.

Topic Closed

This topic has been closed to new replies.

About this Topic