简体   繁体   中英

How to Add Previous Page, Next Page, First Page, Last Page in the Pagination?

I want to know how can i add next page, previous page, first page and last page in this pagination. Below code is only showing the page number it doesn't show next page, previous page, first page and last page.

    <?php
            $pagesToShow = 10; 
            $pageSize = 20; 
            $numPages = ceil($numResults / $pageSize); 
            $pageLefts = min($pagesToShow, $numPages); 
            $currentPage = $page - floor( $pagesToShow / 2 ); 
            if($currentPage < 1){ 
                $currentPage = 1;
            }
            if($currentPage + $pageLefts > $numPages + 1) {
                $currentPage = $numPages + 1 - $pageLefts;
            }
            while($pageLefts != 0 && $currentPage <= $numPages) { 
                if($currentPage == $page){
                    echo "<div class='pageNumberContainer'>

                        <span class='pageNumber'>$currentPage</span>
                      </div>";
                }else{
                    echo "<div class='pageNumberContainer'>
                              <a href='search.php?term=$term&type=$type&page=$currentPage'>

                                <span class='pageNumber'>$currentPage</span>
                              </a>
                          </div>";
                }
                $currentPage++;
                $pageLefts--;
            }

            ?>

I dont know if this helps .. but maybe you can do something with it :)

 <?php      $pagesToShow = 10; 
        $pageSize = 20; 
        $numPages = ceil($numResults / $pageSize); 
        $pageLefts = min($pagesToShow, $numPages); 
        $currentPage = $page - floor( $pagesToShow / 2 ); 
        if($currentPage < 1){ 
            $currentPage = 1;
        }
        if($currentPage + $pageLefts > $numPages + 1) {
            $currentPage = $numPages + 1 - $pageLefts;
        }
        if ($numPages > 1){echo 'FirstPage = 1';}
        while($pageLefts != 0 && $currentPage <= $numPages) { 
            if($currentPage == $page){

                echo "<div class='pageNumberContainer'>

                    <span class='pageNumber'>Current Page Number Is: ".$currentPage</span>
                  </div>";
            }else{

                if ($currentPage != 1){$previousPage = $currentPage - 1; echo 
'PREVIOUS PAGE:' . $previousPage; }
                echo "<div class='pageNumberContainer'>
                          <a href='search.php?term=".$term."&type=".$type."&page=".$currentPage."'>

                            <span class='pageNumber'>CURRENT PAGE: ".$currentPage." </span>
                          </a>
                      </div>";
                if ($currentPage != $numPages){$nextPage = $currentPage + 1; echo 'NEXT PAGE:' . $nextPage; }     

            }
            $currentPage++;
            $pageLefts--;
        }
        if ($numPages > 1){echo 'LastPage = '.$numPages;}
       ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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