how can i do pagination without reaload page in wordpress

Posted by Swap on Stack Overflow See other posts from Stack Overflow or by Swap
Published on 2012-12-13T04:07:46Z Indexed on 2012/12/13 5:04 UTC
Read the original article Hit count: 154

Filed under:
|
|
|
|

how can i do pagination without reaload page in wordpress. i have use following code for the pagination but here page is reaload for each pagination. what can i do to stop realod page???please suggest me.

<?php
                       $page = (get_query_var('page')) ? get_query_var('page') : 1     

                       $limit=10;
                       $offset = ( $page - 1 ) * $limit;    
                      $data = $wpdb->get_results("select * from wp_products order by product_id  $sort_by
                                          LIMIT $offset,$limit ");
                 $total=$wpdb->get_results("select * from wp_products ");
            $pages = COUNT($total);
            $pages = ceil($pages / $limit);
            $querystring = "";
            foreach ($_GET as $key => $value) {
                if ($key != "page") $querystring .= "$key=$value&amp;";
            }

            // Pagination
            ?>


     <div class="pagination">
               <?php
              if( $pages > 1)
              {
                $range=1;
                $showitems = ($range * 2)+1;  
                $page1=$page;
                $prev=$page1-1;
                if($page > 1)
                {
                    echo "<a  class=\"page gradient\" ";
                    echo "href=\"?{$querystring}page=$prev";
                    echo "\">Previous</a> ";
                }
                for ($i = 1; $i <= $pages; $i++)
                   {
                        if (1 != $pages &&( !($i >= $page+$range+1 || $i <= $page-$range-1) || $pages <= $showitems ))
                             {
                                if($i == $page) 
                                { 
                                    echo  "<span class=\" page active\">".$i."</span>";
                                }
                                else
                                { 

                                echo "<a class=\"page gradient\"";
                                echo "href=\"?{$querystring}page=$i";
                                echo "\">$i</a> ";
                                }

                             }
                        }
                        if($page!=$pages)
                        {
                        if($showitems < $pages)
                            {
                                echo "..... ";
                            }
                            $page1=$page;
                            $next=$page1+1;
                            echo "<a " . ($i == $page ? "class=\"page active\" " : "class=\"page gradient\"");
                            echo "href=\"?{$querystring}page=$next";
                            echo "\">Next</a> ";
                        }
              }
                ?>                                         
                </div>

© Stack Overflow or respective owner

Related posts about php

Related posts about JavaScript