Pagination working on subpage but not homepage (3 posts)

  1. choazie
    Posted 5 years ago #

    Hi guys

    I was using this code on a subpage and the pagination worked fine:

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('category_name=Uncategorized&posts_per_page=10&paged=' . $paged); ?>
     <?php if(function_exists('wp_paginate')) {
    } ?>
    <?php while (have_posts()) : the_post(); ?>

    Then I set the subpage (http://www.ratethishunk.com/latest) to homepage (http://www.ratethishunk.com) through the WordPress reading settings ("Frontpage displays static page"). On the homepage the paginator displays the same posts on all pages. So e.g. http://www.ratethishunk.com/page/2/ displays the same posts as http://www.ratethishunk.com/page/3/.

    Any help would be appreciated. Thank you!

    Note: this is not the same problem as I posted last month: http://wordpress.org/support/topic/recent-posts-with-paginator-problem-help?replies=2

  2. choazie
    Posted 5 years ago #

    Please help!

    Thank you.

  3. nothingspare
    Posted 5 years ago #

    The problem does seem to be specific to homepage pagination. The way this plugin determines the page will always return the paginated links for page 1 by default, while working everywhere else on the site.

    You can set your own page number during your call to wp_paginate( $args ) by passing it into the $args array. This is an admittedly ugly solution, but I got it working by adding these two functions to the functions.php file:

    function bw_get_page_number( $args = array() ){
    	$url =  preg_split( '/\/page\//' , current_page_url() );
    	$page = get_query_var( 'paged' );
    	if( !$page ){
    		if( !empty( $url[1] ) ){
    			$page = preg_replace( '/[^0-9]/' , '' , $url[1] );
    		} else {
    			$page = 1;
    	if( $page < 2 ){ $page = 1; }
    	return $page;
    function bw_get_page_count(){
    	global $wp_query;
    	$posts_per_page = intval( get_query_var( 'posts_per_page' ) );
    	$pages = intval( ceil( $wp_query->found_posts / $posts_per_page ) );
    	return $pages;

    And the call to wp_paginate( $args ) looks as follows:

    $args = array( 'page' => bw_get_page_number() , 'pages' => bw_get_page_count() );
    echo wp_paginate( $args );

    There may be several reasons why this will not immediately work for you, so I'll be sure to check back on this topic for your reply.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP-Paginate
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic