Bom dia moçada.
Seguinte:
Estou usando uma função apara paginação, funciona beleza, porém a exibição dos links é infinita. Preciso de uma paginação apresentando no máximo 5 links, de 1 a 5.
Peço ajuda para ajustar esse detalhe no seguinte código.
public function rowCount() { return @mysql_affected_rows(); } public function getUrl( $perpage ) { $this->url = $_SERVER['REQUEST_URI']; return $this; } public function paginate( $perpage ) { $this->pagination = true; $this->perpage = $perpage; return $this; } public function paginateLink() { if ( $this->url != null ) { if ( !preg_match( '/\?/', $this->url ) ) { $this->url .= "?"; } else { $this->url .= "&"; } } else { //$this->url = "?"; } if ( isset( $_GET['page'] ) ) { $this->current = $_GET['page']; $this->page = $this->perpage * $_GET['page'] - $this->perpage; if ( $_GET['page'] == 1 ) { $this->page = 0; } } $this->total = $this->rows; if ( $this->rows > $this->perpage ) { $this->link = "<div class=\"pagination\"><ul>"; $prox = "javascript:;"; $ant = "javascript:;"; if ( $this->current >= 2 ) { $ant = $this->url . "page=" . ($this->current - 1); } if ( $this->current >= 1 && $this->current < ($this->total / $this->perpage) ) { $prox = $this->url . "page=" . ($this->current + 1); } $this->link .= '<li><a href="' . $ant . '">«</a></li>'; $from = round( $this->total / $this->perpage ) ; if($from == 1){$from++;} for ( $i = 1; $i <= $from; $i++ ) { if ( $this->current == $i ) { $this->link .= "<li class=\"active\"><a>$i</a></li>\n"; } else { $this->link .= "<li><a href=\"" . $this->url . "page=$i\">$i</a></li>\n"; } } $this->link .= '<li><a href="' . $prox . '">»</a></li>'; $this->link .= "</ul>\n"; $this->link .= "</div>\n"; } return $this; } public function cut( $str, $chars, $info= '' ) { if ( strlen( $str ) >= $chars ) { $str = preg_replace( '/\s\s+/', ' ', $str ); $str = strip_tags( $str ); $str = preg_replace( '/\s\s+/', ' ', $str ); $str = substr( $str, 0, $chars ); $str = preg_replace( '/\s\s+/', ' ', $str ); $arr = explode( ' ', $str ); array_pop( $arr ); //$arr = preg_replace('/\ /i',' ',$arr); $final = implode( ' ', $arr ) . $info; } else { $final = $str; } return $final; }
Desde já, agradeço.