Pagination not working on static page

Dear I have wasted my week on this problem, basically when you select static page as your home page in setting->reading of wordpress the complete behavior of listing things are changed, basically static pages are never meant for pagination the fact is when you call the $paged variable it will always return zero even if you define its value to 1 the pagination will just refresh your page, because its a page not a .php valid file page is already a taxonomy function that is called in index.php of main wordpress the function will always return same thing no matter what you do,

The work around make a index.php file copy all the content from that static page to it and then replace it with your index.php and select latest post in setting->reading of wordpress

Now if you really don’t want to mess with it, but still want to have the pagination then you need to write a small code of yours for pagination

basically home.com/page/2 will never work but home.com/?page=2 will always work but changing the permalink structure will change it for every thing so we will create a pagination function that will call next page with home.com/?page=2 structure url

/* ------------------------------------------------------------------*/
/* PAGINATION */
/* ------------------------------------------------------------------*/

//paste this where the pagination must appear

global $wp_query;
$total = $wp_query->max_num_pages;
// only bother with the rest if we have more than 1 page!
if ( $total > 1 )  {
     // get the current page
     if ( !$current_page = get_query_var('paged') )
          $current_page = 1;
     // structure of "format" depends on whether we're using pretty permalinks
     if( get_option('permalink_structure') ) {
         $format="?paged=%#%";
     }
     echo paginate_links(array(
          'base'     => get_pagenum_link(1) . '%_%',
          'format'   => $format,
          'current'  => $current_page,
          'total'    => $total,
          'mid_size' => 4,
          'type'     => 'list'
     ));
}

if you include this code where this rather than the current pagination you will see it working 🙂

Leave a Comment