I am using codeigniter's default pagination
< 1 2 3 4 >
but I'd like to make it to this format
< 1-10 11-20 21-30 >
any ideas?
Good Question: You will need to extend code system/CI_Pagination.php
library into application/library/MY_Pagination.php
Math Calculation by @Dan is fine, setup into CI
Pagination Library, see below
1) Create file into application/library/MY_Pagination.php
more info
about Create Library
Overwrite create_links()
method from custom method, see below
Revised code section in create_links()
method
if ($this->cur_page === $loop){
// Current page
$output .= $this->cur_tag_open.($this->cur_page == 1 ? $loop : $loop*($this->per_page)+1).'-'.($loop * $this->per_page).$this->cur_tag_close;
}elseif ($i === $base_page){
// First page
$output .= $this->num_tag_open.'<a href="'.$first_url.'"'.$attributes.$this->_attr_rel('start').'>'
.((($loop)*($this->per_page) - $this->per_page)+1) .'-'. ($loop * $this->per_page).'</a>'
.$this->num_tag_close;
}else{
$append = $this->prefix.$i.$this->suffix;
$output .= $this->num_tag_open.'<a href="'.$base_url.$append.'"'.$attributes.$this->_attr_rel('start').'>'
.((($loop)*($this->per_page) - $this->per_page)+1) .'-'. ($loop * $this->per_page)
.'</a>'.$this->num_tag_close;
}
Full MY_Pagination.php file Line no(577-592) click here
NOTE I have used latest core file so please use you amendment in your current file
Do some simple math to adjust, so for example if $x = 1
Instead of page 1 being $x page 1 is:
<?php echo $x.'-'.($x * 10); ?>
Page 2 and higher is:
<?php
$x++;
echo (($x)*10)-10)+1.'-'.($x * 10);
?>
Where $x++
counts up for each display.
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.