WordPress pagination not working on home page ( Custom templete )

I have googled the problem, I am worried not only me there are many coder who faces this problem. I applied there fixing but same result. Would you please review my pagination code? I have a static front page, where pagination redirects me to homepage (/). If I add after url /page/2 manually this one also redirect me to homepage. I know this is childish question but I can’t figure out the problem.

This is the function.

Read More
 function pagination($pages = '', $range = 2)
 {  
     $showitems = ($range * 2)+1;  

     global $paged;
     if(empty($paged)) $paged = 1;

     if($pages == '')
     {
         global $wp_query;
         $pages = $wp_query->max_num_pages;
         if(!$pages)
         {
             $pages = 1;
         }
     }   

     if(1 != $pages)
     {
         echo "<ul class='pagenavi'>";
         if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link(1)."'>&laquo;</a></li>";
         if($paged > 1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link($paged - 1)."'>&lsaquo;</a></li>";

         for ($i=1; $i <= $pages; $i++)
         {
             if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
             {
                 echo ($paged == $i)? "<li><a href='".get_pagenum_link($i)."' class='current' >".$i."</a></li>":"<li><a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a></li>";
             }
         }

         if ($paged < $pages && $showitems < $pages) echo "<li><a href='".get_pagenum_link($paged + 1)."'>&rsaquo;</a></li>";  
         if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<li><a href='".get_pagenum_link($pages)."'>&raquo;</a></li>";
         echo "</ul>n";
     }
}

Code used to generate pagination

<?php query_posts( array( 'post_type' => 'post', 'paged' => $paged, 'cat'=> $bcatid, 'posts_per_page' => 9 ) );
?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
post content
<?php endwhile; endif; ?>
<?php pagination(); ?>

Thanks in advance for your valuable time.

Related posts

Leave a Reply

1 comment