简体   繁体   English

我如何在没有WordPress的重载页面的情况下进行分页

[英]how can i do pagination without reaload page in wordpress

how can i do pagination without reaload page in wordpress. 如何在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>

How about trying something like this: 如何尝试这样的事情:

$('.page').click(function(e) {
    e.preventDefault();
    $.ajax({url: $(this).prop('href'), success: function(d) {
        var page = $(d).find('.pagination').html();
        $('.pagination').html(page);
    }});
});

This uses jQuery to disable the normal click event of the next link, grabs the href of the next link, makes an AJAX request to the next page, save the HTML of the next page's pagination div, and replaces the current page's pagination div with the new one. 这使用jQuery禁用下一个链接的常规click事件,获取下一个链接的href,向下一个页面发出AJAX请求,保存下一个页面的分页div的HTML,并将当前页面的分页div替换为新的一个。

Just fetch all pages at once and then on same page use jquery datatable js for pagination in such case page will not reload. 只需一次获取所有页面,然后在同一页面上使用jquery datatable js进行分页,在这种情况下将不会重新加载页面。 Datatable example here. 这里的数据表示例。

http://datatables.net/examples/basic_init/alt_pagination.html http://datatables.net/examples/basic_init/alt_pagination.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM