Break up PHP Pagination links
Posted
by Rabbott
on Stack Overflow
See other posts from Stack Overflow
or by Rabbott
Published on 2010-05-16T16:16:41Z
Indexed on
2010/05/16
16:20 UTC
Read the original article
Hit count: 202
php
|pagination
I have the following method that creates and returns markup for my pagination links in PHP.
public function getPaginationLinks($options) {
if($options['total_pages'] > 1) {
$markup = '<div class="pagination">';
if($options['page'] > 1) {
$markup .= '<a href="?page=' . ($options['page'] - 1) . ((isset($options['order_by'])) ? "&sort=" . $options['order_by'] : "") . '">< prev</a>';
}
for($i = 1; $i <= $options['total_pages']; $i++) {
if($options['page'] != $i) {
$markup .= '<a href="?page='. $i . ((isset($options['order_by'])) ? "&sort=" . $options['order_by'] : "") . '">' . $i . '</a>';
}
else {
$markup .= '<span class="current">' . $i . '</span>';
}
}
if($options['page'] < $options['total_pages']) {
$markup .= '<a href="?page=' . ($options['page'] + 1) . ((isset($options['order_by'])) ? "&sort=" . $options['order_by'] : "") . '">next ></a>';
}
$markup .= '</div>';
return $markup;
}
else {
return false;
}
}
I just recently discovered (to my surprise) that i had reached 70+ pages which means that there are now 70+ links showing up at the bottom..
I'm wondering if someone can help me break this up.. I'm not sure how most pagination works as far as showing the numbers if im on say.. page 30, ideas?
© Stack Overflow or respective owner