分页页数

I am creating pagination. I have a pagination class:

class Pagination {
    public $current_page;
    public $per_page;
    public $total_count;

    public function __construct($page=1, $per_page=10, $total_count=0){
        $this->current_page = (int)$page;
        $this->per_page = (int)$per_page;
        $this->total_count = (int)$total_count;
    }

    public function offset(){
        // Assuming 20 items per page:
        // page 1 has an offset of 0    (1-1) * 20
        // page 2 has an offset of 20   (2-1) * 20
        //  in other words, page 2 starts with item 21
        return ($this->current_page - 1) * $this->per_page; 
    }

    public function total_pages(){
        return ceil($this->total_count/$this->per_page);    
    }

    public function previous_page(){
        return $this->current_page - 1;
    }

    public function next_page(){
        return $this->current_page + 1;
    }

    public function has_previous_page(){
        return $this->previous_page() >= 1 ? true : false;  
    }

    public function has_next_page(){
        return $this->next_page() <= $this->total_pages() ? true : false;   
    }
}

I also am using it like this:

<?php

    // 1. the current page number ($current_page)
    $page = !empty($_GET['page']) ? (int)$_GET['page'] : 1;

    // 2. records per page
    $per_page = 8;

    // 3. total record count ($total_count)
    $total_count = Song::count_all();

    $pagination = new Pagination($page, $per_page, $total_count);

    // Instead of finding all records, just find the records
    // for this page
    $sql     = "SELECT * FROM songs ";
    $sql    .= "ORDER BY dopeness DESC ";
    $sql    .= "LIMIT {$per_page} ";
    $sql    .= "OFFSET {$pagination->offset()}";
    $songs = Song::find_by_sql($sql);
?>



<?php
    if($pagination->total_pages() > 1){
        if($pagination->has_previous_page()){
            echo "<a href=\"all_songs.php?page=";
            echo $pagination->previous_page();
            echo "\">&laquo;Previous&nbsp;&nbsp;</a> ";
        }

        for($i=1; $i<=$pagination->total_pages(); $i++){
            if($i == $page){
                echo " <span class=\"selected\">{$i}</span> ";
            } else {
                echo " <a href=\"all_songs.php?page={$i}\">{$i}</a> ";
            }
        }

        if($pagination->has_next_page()){
            echo "<a href=\"all_songs.php?page=";
            echo $pagination->next_page();
            echo "\">&nbsp;&nbsp;Next&raquo;</a> ";
        }
    }

?>

Output is "previous 1 2 3 (however many pages) next". What I want to do is make it so that if there are more than ten pages there will be "..." for the last link that would take you to page 11-20 ("previous 11 12 13 next") and so on. Can anybody help me to tackle this?

You should not only display the next 10 pages starting with 0, but consider the current page - then walk 10 pages on wards, and break the iteration, once you displayed 10 page-buttons:

    $page = 5; //assuming within valid bounds

    for($i=$page; $i<=$pagination->total_pages(); $i++){
        if ($i > $page+ 10){
           echo " ... ";
           break;
        }

        if($i == $page){
            echo " <span class=\"selected\">{$i}</span> ";
        } else {
            echo " <a href=\"all_songs.php?page={$i}\">{$i}</a> ";
        }
    }