WordPress.org

Ready to get started?Download WordPress

Forums

WP-PageNavi
[resolved] Pagination not working when I use a custom query (4 posts)

  1. Icethrill
    Member
    Posted 3 years ago #

    I am having trouble with wp_pagenavi working on the start page using a custom query. Its working well on every standard template like category.php. But not on the startpage.

    Here is the code:

    $args = array(
    	'post_type' => 'post',
    	'orderby' => 'date',
    	'posts_per_page' => 3,
    	'paged' => get_query_var('paged'),
    );
    query_posts( $args );
    
    if (have_posts()) : while (have_posts()) : the_post();
    
    	echo the_title();
    
    	endwhile;
    endif;
    
    if(function_exists('wp_pagenavi'))
    	wp_pagenavi();

    The pagination shows up, but the url /page/2/ is not working, it shows /page/1/ result.

    http://wordpress.org/extend/plugins/wp-pagenavi/

  2. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    As you said yourself, the pagination is working. What's not working is your query.

    Are you sure the same template is loaded in both cases? i.e. front-page.php vs. home.php

  3. Icethrill
    Member
    Posted 3 years ago #

    I have tried your fix which you state here. But it did not work for me.

    I am not sure if its the same template, it has the same design and layout as my front-page.php - So it should be the same template I think.

    Any ideas what I am doing wrong? What is wrong in my query?

  4. Icethrill
    Member
    Posted 3 years ago #

    Found a fix, I changed the query to:

    $args = array(
    	'post_type' => 'post',
    	'orderby' => 'date',
    	'posts_per_page' => 3,
    	'paged' => get_query_var('page'),
    );
    query_posts( $args );

    Changed it from paged to page in get_query_var. Works superb!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic