0
votes

I have implemented a pagination links at the end of my wordpress blog page. In a one page I have 3 posts and when I click the next link of my pagination links it take me to the next page which contains the next 3 posts. I retrieve posts from only one category. But when I go to the next page the html title of that page is "Page not found" My code is like below:

  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  $args = array('cat'=> 4, 'posts_per_page' => 3, 'paged' => $paged );
   query_posts($args); 
        if(have_posts()) :
         print ('<div class="row">'); 
     while (have_posts()) : the_post();
       $excerpt = get_the_excerpt();    
              //My post contents
         endwhile;
              if (function_exists("pagination")) {
       pagination();
     }
        print ('<!-- end main row --></div>');
       endif;       
  }

My pagination function is:

   function pagination() {
  /*
  post: retun the pagination post cout and next previous buttons
  */    
       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) {
        print('<section >');        
     if ($paged < $pages)   
                 echo "<a  href=\"".get_pagenum_link($paged + 1)."\">NEXT</a>"; 
       if($paged <= $pages && $paged > 1) 
         echo "<a  href='".get_pagenum_link($paged - 1)."'>BACK</a>";
             echo "<p >Page ".$paged." of ".$pages."</p>";
              echo "</section>";
          }
  }

Please help me for this

2
I think wordpress wp_title() function is not supported for my page in this case.I use get_pagenum_link() function to load the next page is this correct?Chathuraka

2 Answers

0
votes

Try this insteatd

<?php
$big = 999999999; // need an unlikely integer

echo paginate_links( array(
    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    'format' => '?paged=%#%',
    'current' => max( 1, get_query_var('paged') ),
    'total' => $the_query->max_num_pages
) );
?>
0
votes

Try to add this

paginate_links(array(
              'base' => get_pagenum_link(1) . '%_%',
              'format' => 'page/%#%',
              'current' => $current_page,
              'total' => $total_pages,
              'cat' => 4,
            ));

You missed category ID (cat=>4)

also change:

ADMIN PANEL -> SETTING -> READING -> Blog pages show at most : 3 as per $args = array('cat'=> 4, 'posts_per_page' => 3, 'paged' => $paged );