public function render(\Koch\Pagination\Pagination $pagination) { $current_page = $pagination->getCurrentPage(); $total_pages; $html = '<nav class="pagination">' . _('Pages'); if ($current_page > 3) { $html .= sprintf('<a href="%s">1</a>', str_replace('{page}', 1, $url)); if ($current_page !== 4) { $html .= '…'; } } // render page range around the current page for ($i = $current_page - 2, $stop = $current_page + 3; $i < $stop; ++$i) { if ($i < 1 or $i > $total_pages) { continue; } if ($current_page === $i) { $html .= sprintf('<li class="active">%s</li>', $i); } else { $html .= sprintf('<a href="%s">$s</a>', str_replace('{page}', $i, $url), $i); } } if ($current_page <= $total_pages - 3) { if ($current_page !== $total_pages - 3) { $html .= '…'; } $html .= sprintf('<a href="%s">%s</a>', str_replace('{page}', $total_pages, $url), $total_pages); } $html .= '</nav>'; return $html; }
public function render(\Koch\Pagination\Pagination $pagination) { $lastPage = $pagination->getLastPage(); $numberOfPages = $pagination->getNumberOfPages(); $current_page = $pagination->getCurrentPage(); $url = 'URL'; $html = '<nav class="pagination">'; $html .= sprintf('<a href="%s">‹ %s</a>', str_replace('{page}', 1, $url), _('First')); if ($pagination->hasPreviousPage()) { $html .= sprintf('<a href="%s"><</a>', str_replace('{page}', $pagination->getPreviousPage(), $url)); } // render page range around the current page for ($i = 1; $i <= $numberOfPages; ++$i) { if ($i === $current_page) { $html .= sprintf('<li class="active">%s</li>', $i); } else { $html .= sprintf('<a href="%s">%s</a>', str_replace('{page}', $i, $url), $i); } } if ($pagination->hasNextPage()) { $html .= sprintf('<a href="%s">></a>', str_replace('{page}', $pagination->getNextPage(), $url)); } if ($lastPage) { $html .= sprintf('<a href="%s"> %s›</a>', str_replace('{page}', $lastPage, $url), _('Last')); } $html .= '</nav>'; return $html; }
public function render(\Koch\Pagination\Pagination $pagination) { $html = '<nav class="pagination">'; if ($previous_page) { $html .= sprintf('<a href="%s">« %s </a>', str_replace('{page}', $pagination->getPreviousPage(), $url), _('previous')); } else { $html .= '« ' . _('previous'); } $html .= '|'; $html .= sprintf('%s, %s, %s, %s', _('Page'), $current_page, _('of'), $total_pages); $html .= '|'; $html .= sprintf('%s, %s, – %s %s %s', _('Items'), $current_first_item, $current_last_item, _('of'), $total_items); $html .= '|'; if ($pagination->hasNextPage()) { $html .= sprintf('<a href="%s"> %s »</a>', str_replace('{page}', $pagination->getNextPage(), $url), _('Next')); } else { $html .= _('pagination.next') . ' »'; } $html .= '</nav>'; return $html; }
public function render(\Koch\Pagination\Pagination $pagination) { $current_page = $pagination->getCurrentPage(); $next_page = $pagination->getNextPage(); $previous_page = $pagination->getPreviousPage(); $html = '<nav class="pagination">'; if ($previous_page) { $html .= sprintf('<a href="%s">« %s</a>', str_replace('{page}', $previous_page, $url), _('Previous')); } else { $html .= '« ' . _('Previous'); } if ($total_pages < 13) { /* « Previous 1 2 3 4 5 6 7 8 9 10 11 12 Next » */ for ($i = 1; $i <= $total_pages; ++$i) { if ($i === $current_page) { $html .= sprintf('<li class="active">%s</li>', $i); } else { $html .= sprintf('<a href="%s">%s</a>', str_replace('{page}', $i, $url), $i); } } } elseif ($current_page < 9) { /* « Previous 1 2 3 4 5 6 7 8 9 10 … 25 26 Next » */ for ($i = 1; $i <= 10; ++$i) { if ($i === $current_page) { $html .= sprintf('<li class="active">%s</li>', $i); } else { $html .= sprintf('<a href="%s">%s</a>', str_replace('{page}', $i, $url), $i); } } $html .= '…'; $html .= sprintf('<a href="%s">%s</a>', str_replace('{page}', $total_pages - 1, $url), $total_pages - 1); $html .= sprintf('<a href="%s">%s</a>', str_replace('{page}', $total_pages, $url), $total_pages); } elseif ($current_page > $total_pages - 8) { /* « Previous 1 2 … 17 18 19 20 21 22 23 24 25 26 Next » */ $html .= sprintf('<a href="%s">1</a>', str_replace('{page}', 1, $url)); $html .= sprintf('<a href="%s">2</a>', str_replace('{page}', 2, $url)); $html .= '…'; for ($i = $total_pages - 9; $i <= $total_pages; ++$i) { if ($i === $current_page) { $html .= sprintf('<li class="active">%s</li>', $i); } else { $html .= sprintf('<a href="%s">%s</a>', str_replace('{page}', $i, $url), $i); } } } else { /* « Previous 1 2 … 5 6 7 8 9 10 11 12 13 14 … 25 26 Next » */ $html .= sprintf('<a href="%s">1</a>', str_replace('{page}', 1, $url)); $html .= sprintf('<a href="%s">2</a>', str_replace('{page}', 2, $url)); $html .= '…'; // render page range around the current page for ($i = $current_page - 5; $i <= $current_page + 5; ++$i) { if ($i === $current_page) { $html .= sprintf('<li class="active">%s</li>', $i); } else { $html .= sprintf('<a href="%s">%s</a>', str_replace('{page}', $i, $url), $i); } } $html .= '…'; $html .= sprintf('<a href="%s">%s</a>', str_replace('{page}', $total_pages - 1, $url), $total_pages - 1); $html .= sprintf('<a href="%s">%s</a>', str_replace('{page}', $total_pages, $url), $total_pages); } if ($next_page) { $html .= sprintf('<a href="%s">%s »</a>', str_replace('{page}', $next_page, $url), _('Next')); } else { $html .= _('Next') . ' »'; } $html .= '</nav'; return $html; }