• Resolved ndrwld

    (@ndrwld)


    Hi, I’ve changed my pagination base. But unfortunately with new links Wp PageNavi pagination doesn’t work. So far I can’t understand why it is so. Any help would be greatly appreciated.

    I change my pagination base with this code (‘pages’ – are new pagination base):

    function custom_pagination_base() {
    	global $wp_rewrite;
    
    	$pagination_base = get_option( 'pagination_base' );
    	$wp_rewrite->pagination_base = empty( $pagination_base ) ? 'pages' : $pagination_base;
    }
    add_action( 'init', 'custom_pagination_base' );

    Do you have any plans to add pagination base option to future plugin releases?

    I’ve found useful plugin which changes author base. Pagination base can be changed the same way.

    Thank you for any help.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author scribu

    (@scribu)

    PageNavi uses the get_pagenum_link() function from WP, so pagination base is supported.

    Did you flush the rewrite rules after changing the pagination base?

    You can do that by simply accessing WP Admin -> Settings -> Permalinks.

    Thread Starter ndrwld

    (@ndrwld)

    Thanks scribu for your response.
    Yes I did flush rewrite rules. I also tried on my other wordpress installation with all plugins disabled.

    Is it possible that the problem in posts loop? I’m calling posts through WP_Query class.

    $loop = new WP_Query( array( 'post_type' => 'post', 'ignore_sticky_posts' => 0, 'posts_per_page' => '5', 'paged' => get_query_var( 'paged' ) ) );
    	while ( $loop->have_posts() ) : $loop->the_post();
            ......
    	endwhile; // End the loop.

    and then calling wp_pagenavi with:

    if ( function_exists('wp_pagenavi') )
        wp_pagenavi( array( 'query' => $loop ) );
    Plugin Author scribu

    (@scribu)

    Just try calling the normal prev/next page controls and see how they behave:

    wp_pagenavi( array( 'query' => $loop ) );
    
    next_posts_link();
    
    previous_posts_link();
    Thread Starter ndrwld

    (@ndrwld)

    There is really strange behavior. When I’m adding

    next_posts_link();
    previous_posts_link();

    The next_posts_link() shows nothing. When I click on Pagenavi links the end of url is “..page/2/pages/2/”, after flushing permalinks too, and it’s still the same after bringing everything back.

    I’ll try this on fresh installation. step by step and try to figure out where is the problem.

    Thread Starter ndrwld

    (@ndrwld)

    I’ve found the problem. It was in custom_pagination_base function. The new one is:

    function custom_pagination_base() {
    	global $wp_rewrite;
    
      // Change the value of the author permalink base to whatever you want here
    	  $wp_rewrite->pagination_base = 'pages';
    
    	  $wp_rewrite->flush_rules();
    }
    add_action( 'init', 'custom_pagination_base' );

    However this works only for default post types (I didn’t tried it with pages).
    Unfortunately it doesn’t work with custom post types. And I don’t know why.

    If pagination base is hardcoded in wp-includes/rewrite.php – everything works fine.

    Thread Starter ndrwld

    (@ndrwld)

    I’ve found the solution, to not hardcode pagination base. Place this code into your theme functions.php or ../wp-content/mu-plugins.
    Just add priority number to the function:

    function custom_pagination_base() {
    	global $wp_rewrite;
    
      // Change the value of the author permalink base to whatever you want here
    	  $wp_rewrite->pagination_base = 'new-pagination-base';
    
    	  $wp_rewrite->flush_rules();
    }
    add_action( 'init', 'custom_pagination_base', 1 );

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Change pagination_base’ is closed to new replies.